Author Topic: Prompt for User Input | Left, Right Arrow?  (Read 6304 times)

0 Members and 1 Guest are viewing this topic.

BlackBox

  • King Gator
  • Posts: 3770
Prompt for User Input | Left, Right Arrow?
« 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.  :|
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Prompt for User Input | Left, Right Arrow?
« Reply #1 on: August 10, 2011, 03:48:50 PM »
I've mimicked it, but never found a way to read it.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Prompt for User Input | Left, Right Arrow?
« Reply #2 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), was the use of NirCmd.exe
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Prompt for User Input | Left, Right Arrow?
« Reply #3 on: August 10, 2011, 04:05:04 PM »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Prompt for User Input | Left, Right Arrow?
« Reply #4 on: August 10, 2011, 04:07:12 PM »
Nevermind, just read your link.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

BlackBox

  • King Gator
  • Posts: 3770
Re: Prompt for User Input | Left, Right Arrow?
« Reply #5 on: August 10, 2011, 04:22:09 PM »
"How we think determines what we do, and what we do determines what we get."

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Prompt for User Input | Left, Right Arrow?
« Reply #7 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);
            }
        }
         

BlackBox

  • King Gator
  • Posts: 3770
Re: Prompt for User Input | Left, Right Arrow?
« Reply #8 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
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Prompt for User Input | Left, Right Arrow?
« Reply #9 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;
                }
         
            }
        }

 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Prompt for User Input | Left, Right Arrow?
« Reply #10 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

BlackBox

  • King Gator
  • Posts: 3770
Re: Prompt for User Input | Left, Right Arrow?
« Reply #11 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:
"How we think determines what we do, and what we do determines what we get."

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Prompt for User Input | Left, Right Arrow?
« Reply #12 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
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BlackBox

  • King Gator
  • Posts: 3770
Re: Prompt for User Input | Left, Right Arrow?
« Reply #13 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.
"How we think determines what we do, and what we do determines what we get."