Sign in to follow this  
Followers 0
RichardL

Want GUI to detect arrow keys pressed

3 posts in this topic

Hello,

I have a problem where a special keyboard for a piece of equipment is unavailable. So I want a GUI to detect all keypresses (then I can convert them to text messages and 'Send' them to a telnet window.)

I'm using a GUI prog modified from GaryFrost), but it's not detecting the arrow keys.

Thanks,

Richard.

#include <GuiConstants.au3>
#include <Date.au3>

Global Const $WM_NOTIFY         = 0x004E
Global Const $WM_NCRBUTTONDOWN  = 0x00A4
Global Const $WM_KEYDOWN        = 0x0100
Global Const $WM_SYSKEYDOWN     = 0x0104
Global Const $WM_SYSCHAR        = 0x0106
Global Const $WM_COMMAND        = 0x0111
Global Const $WM_IME_KEYDOWN    = 0x0290


Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nNotifyCode  = _HiWord($wParam)
    Local $nID                  = _LoWord($wParam)
    Local $hCtrl                = $lParam

    ConsoleWrite(StringFormat("WMC %s %4x %4x %4x %8x\n", _Now(), $msg, $nNotifyCode, $nID, $hCtrl))
    Return $GUI_RUNDEFMSG
EndFunc


GUICreate("MyGUI")

GUISetState()
GUIRegisterMsg($WM_KEYDOWN,       "MY_WM_COMMAND")
; Try others to find arrow keypresses...
GUIRegisterMsg($WM_COMMAND,       "MY_WM_COMMAND")
GUIRegisterMsg($WM_SYSKEYDOWN,    "MY_WM_COMMAND")
GUIRegisterMsg($WM_SYSCHAR,       "MY_WM_COMMAND")
GUIRegisterMsg($WM_NOTIFY,        "MY_WM_COMMAND")
GUIRegisterMsg($WM_NCRBUTTONDOWN, "MY_WM_COMMAND")
GUIRegisterMsg($WM_IME_KEYDOWN,   "MY_WM_COMMAND")

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I read about it in MSDN - WM_KEYDOWN Message

As i can see WM_KEYDOWN value is 0x100 in the remarks says something interesting.

For enhanced 101- and 102-key keyboards, extended keys are the right ALT and CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and ENTER keys in the numeric keypad. Other keyboards may support the extended-key bit in the lParam parameter.

So i do some tests and it works

#include <GuiConstants.au3>
#include <windowsconstants.au3>

GUICreate("MyGUI")

GUISetState()
GUIRegisterMsg(0x101,"WM_KEYDOWN")


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
Func WM_KEYDOWN($hWnd, $msg, $wParam, $lParam)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $wParam = ' & $wParam & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
EndFunc
Edited by monoscout999

Share this post


Link to post
Share on other sites

Oh yes, arrow keys send WM_KEYUP (0x101) but not WM_KEYDOWN. The other keys in that list e.g. home, send both, so the doc does not explain it all. I should have tried both, not blindly assumed.

Thanks,

Richard.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0