TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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. :|
-
I've mimicked (http://msdn.microsoft.com/en-us/library/8c6yea83%28VS.85%29.aspx)it, but never found a way to read it.
-
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
-
NirCmd.exe
What's that?
-
Nevermind, just read your link.
-
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)
-
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
-
You can try this
Add this to one of your practice files
You will need to add
using System.Windows.Interop;
And you might need to reference Windows.Base
Just run CaptureKeys command
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);
}
}
-
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
-
You can try this
Add this to one of your practice files
You will need to add
using System.Windows.Interop;
And you might need to reference Windows.Base
Just run CaptureKeys command
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.
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;
}
}
}
-
Forgot you are a VB guy
and add
Imports System.Windows.Interop
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
-
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:
-
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
-
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.