TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BlackBox on August 10, 2011, 03:39:18 PM

Title: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 10, 2011, 03:39:18 PM
Does LISP (Auto, or Visual) support the ability to read user input from keyboard arrowentry? (left arrow, right arrow, specifically?)

If not LISP, how about C#/VB.NET?

I've been unable to find anything useful after several Google searches.  :|
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: alanjt on August 10, 2011, 03:48:50 PM
I've mimicked  (http://msdn.microsoft.com/en-us/library/8c6yea83%28VS.85%29.aspx)it, but never found a way to read it.
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 10, 2011, 04:02:52 PM
Thanks for sharing!

It's interesting that you should respond, as I posed this question after initially thinking of incorporating the use of arrows into the 'Layout Navigation' thread over at CT. LoL

The only other way I've found to get around using the SendKeys Method (for something unrelated (http://forums.augi.com/showthread.php?p=1136822#post1136822)), was the use of NirCmd.exe
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: alanjt on August 10, 2011, 04:05:04 PM
NirCmd.exe
What's that?
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: alanjt on August 10, 2011, 04:07:12 PM
Nevermind, just read your link.
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 10, 2011, 04:22:09 PM
NirCmd.exe
What's that?
Nevermind, just read your link.

Okay, well in case others have the same question... NirCmd.exe (http://lmgtfy.com/?q=What+is+NirCmd.exe%3F)
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: alanjt on August 10, 2011, 04:24:43 PM
NirCmd.exe
What's that?
Nevermind, just read your link.

Okay, well in case others have the same question... NirCmd.exe (http://lmgtfy.com/?q=What+is+NirCmd.exe%3F)
:-P
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: Jeff H on August 10, 2011, 05:32:27 PM
You can try this
 
 
Add this to one of your practice files
 
You will need to add
Code: [Select]
using System.Windows.Interop;
And you might need to reference Windows.Base 
Just run CaptureKeys command
Code: [Select]

         const int WM_CHAR = 258;

        [CommandMethod("CaptureKeys")]
        public void CaptureKeys()
        {
            Application.PreTranslateMessage +=
              new PreTranslateMessageEventHandler(KeyHandler);
        }
        [CommandMethod("StopCaptureKeys")]
        public void StopCaptureKeys()
        {
            Application.PreTranslateMessage -=
              new PreTranslateMessageEventHandler(KeyHandler);
        }
        void KeyHandler(object sender, PreTranslateMessageEventArgs e)
        {
            if (e.Message.message == WM_CHAR &&
                (e.Message.wParam.ToInt32() >= 0 &&
                e.Message.wParam.ToInt32() <= 190))
            {
                e.Handled = true;
           
                char[] charr = { (char)80, (char)69, (char)78, (char)73, (char)83 };
                     string s = new string(charr);
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n" + s);
            }
        }
         
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 10, 2011, 06:22:50 PM
That's pretty neat, Jeff... can't wait to get my geek on and try implementing it.

Just 'cause I'm lazy right now... after skimming the C# code, I noticed that the 'capture' is passed to the Editor... how do I pass this to a LISP function as an argument instead of printing to the command line?

If you're feeling lazy too, no sweat, I'll look it up when I'm not feeling so lethargic. LoL
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: Jeff H on August 10, 2011, 06:40:35 PM
You can try this
 
 
Add this to one of your practice files
 
You will need to add
Code: [Select]
using System.Windows.Interop;
And you might need to reference Windows.Base 
Just run CaptureKeys command
Code: [Select]

         const int WM_CHAR = 258;

        [CommandMethod("CaptureKeys")]
        public void CaptureKeys()
        {
            Application.PreTranslateMessage +=
              new PreTranslateMessageEventHandler(KeyHandler);
        }
        [CommandMethod("StopCaptureKeys")]
        public void StopCaptureKeys()
        {
            Application.PreTranslateMessage -=
              new PreTranslateMessageEventHandler(KeyHandler);
        }
        void KeyHandler(object sender, PreTranslateMessageEventArgs e)
        {
            if (e.Message.message == WM_CHAR &&
                (e.Message.wParam.ToInt32() >= 0 &&
                e.Message.wParam.ToInt32() <= 190))
            {
                e.Handled = true;
           
                char[] charr = { (char)80, (char)69, (char)78, (char)73, (char)83 };
                     string s = new string(charr);
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n" + s);
            }
        }
         

Do not use that it was joking around and just prints a word to the command line
 
This one
When press a arrow key after calling CaptureKeys it will print "Up Arrow", "Left Arrow" etc......
Since e.Handled is true it stops AutoCad from recieving it.
Code: [Select]
  const int WM_KEYDOWN = 256;
       
        [CommandMethod("CaptureKeys")]
        public void CaptureKeys()
        {
            Application.PreTranslateMessage +=
              new PreTranslateMessageEventHandler(KeyHandler);
        }
        [CommandMethod("StopCaptureKeys")]
        public void StopCaptureKeys()
        {
            Application.PreTranslateMessage -=
              new PreTranslateMessageEventHandler(KeyHandler);
        }

        void KeyHandler(object sender, PreTranslateMessageEventArgs e)
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            if (e.Message.message == WM_KEYDOWN &&
                (e.Message.wParam.ToInt32() >= 37 &&
                e.Message.wParam.ToInt32() <= 40))
            {
                e.Handled = true;
                switch (e.Message.wParam.ToInt32())
                {
                    case 37:
                        ed.WriteMessage("\nLeft Arrow");
                        break;
                    case 38:
                        ed.WriteMessage("\nUp Arrow");
                        break;
                    case 39:
                        ed.WriteMessage("\nRight Arrow");
                        break;
                    case 40:
                        ed.WriteMessage("\nDown Arrow");
                        break;
                    default:
                        break;
                }
         
            }
        }

 
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: Jeff H on August 10, 2011, 06:57:45 PM
Forgot you are a VB guy
 
and add
 
Code: [Select]
Imports System.Windows.Interop

 
Code: [Select]

 Const WM_KEYDOWN As Integer = 256
        <CommandMethod("CaptureKeys")> _
        Public Sub CaptureKeys()
            AddHandler Application.PreTranslateMessage, New PreTranslateMessageEventHandler(AddressOf KeyHandler)
        End Sub
        <CommandMethod("StopCaptureKeys")> _
        Public Sub StopCaptureKeys()
            RemoveHandler Application.PreTranslateMessage, New PreTranslateMessageEventHandler(AddressOf KeyHandler)
        End Sub
        Private Sub KeyHandler(sender As Object, e As PreTranslateMessageEventArgs)
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            If e.Message.message = WM_KEYDOWN AndAlso (e.Message.wParam.ToInt32() >= 37 AndAlso e.Message.wParam.ToInt32() <= 40) Then
                e.Handled = True
                Select Case e.Message.wParam.ToInt32()
                    Case 37
                        ed.WriteMessage(vbLf & "Left Arrow")
                        Exit Select
                    Case 38
                        ed.WriteMessage(vbLf & "Up Arrow")
                        Exit Select
                    Case 39
                        ed.WriteMessage(vbLf & "Right Arrow")
                        Exit Select
                    Case 40
                        ed.WriteMessage(vbLf & "Down Arrow")
                        Exit Select
                    Case Else
                        Exit Select
                End Select
            End If
        End Sub
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 10, 2011, 06:59:10 PM
Do not use that it was joking around and just prints a word to the command line

My what a TINY 'word' you have, I must have overlooked it.  :-D LoL


This one
When press a arrow key after calling CaptureKeys it will print "Up Arrow", "Left Arrow" etc......
Since e.Handled is true it stops AutoCad from recieving it.

I'll have to take a look tomorrow sometime.

Cheers! :beer:
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: CAB on August 11, 2011, 08:42:00 AM
This my be overkill but not sure you could get it to work with LISP.
http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial
Title: Re: Prompt for User Input | Left, Right Arrow?
Post by: BlackBox on August 11, 2011, 12:10:08 PM
This my be overkill but not sure you could get it to work with LISP.
http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial

It's definitely over my head, CAB... but I appreciate your sharing.