Adele Posted September 17, 2015 Share Posted September 17, 2015 (edited) Hi everyone. I want to detect when any key is pressed with GUIRegisterMsg(). The issue is that, before adding any control to GUI, it works but when I added, it starts to not working. I somehow don't understand the issue's source.For example, by this way it works without any issue :#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUIRegisterMsg($WM_KEYDOWN, "KeyPress") $hGUI = GUICreate("") GUISetState() While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func KeyPress() MsgBox(0, "", "A key has been pressed.") EndFuncBut when I added a label, it starts to not working.#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> GUIRegisterMsg($WM_KEYDOWN, "KeyPress") $hGUI = GUICreate("") ;A control to test the issue, GUIRegisterMsg starts not working after it was added GUICtrlCreateLabel("Test", 10, 10, 300, 300) GUISetState() While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func KeyPress() MsgBox(0, "", "A key has been pressed.") EndFuncI've searched and I couldn't find something interesting with this. Thank you in advance. Edited September 17, 2015 by Adele Link to comment Share on other sites More sharing options...
JohnOne Posted September 17, 2015 Share Posted September 17, 2015 Probably because you have a blocking function in your message handler. You are going to get unexpected behaviour, so a simple answer to why with label? is "unexpected." AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kylomas Posted September 17, 2015 Share Posted September 17, 2015 (edited) Adele,A static control cannot accept keyboard input. One possible workaraound...#include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("") ;A control to test the issue, GUIRegisterMsg starts not working after it was added local $lbl010 = GUICtrlCreateLabel("Test", 10, 10, 200, 200, $ss_sunken) guictrlsetstate($lbl010,$GUI_DISABLE) GUISetState() GUIRegisterMsg($WM_KEYDOWN, "KeyPress") While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func KeyPress($hWnd, $iMsg, $wParam, $lParam) ConsoleWrite($wParam & ' - ' & $lParam & @CRLF) ;MsgBox(0, "", "A key has been pressed.") EndFuncNote - Please heed J1's observation about message handlers. The doc is very specific about their use.kylomasEDIT: Please read the forum rules regarding keyloggers. Edited September 17, 2015 by kylomas Additional info czardas 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Adele Posted September 17, 2015 Author Share Posted September 17, 2015 There isn't a special reason for I use label. I'll prepare a ordinary interface with using GUI controls like input, label... As well as when I pressed to any key, the program will detect that. Link to comment Share on other sites More sharing options...
kylomas Posted September 17, 2015 Share Posted September 17, 2015 You may not have seen my edit. Please read the forum rules regarding keyloggers.kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Adele Posted September 17, 2015 Author Share Posted September 17, 2015 (edited) I don't make a program similar keylogger. Only the program's window is active, it should detect key pressing. I prepare a screensaver. I don't need to get which key was pressed. I need to detect when any key was pressed. Edited September 17, 2015 by Adele Link to comment Share on other sites More sharing options...
kylomas Posted September 17, 2015 Share Posted September 17, 2015 Adele,Glad to hear it. You may be interested in _WinAPI_GetIdleTime. See the Help file.kylomas Adele 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Adele Posted September 17, 2015 Author Share Posted September 17, 2015 @kylomas Thank you, I guess this will help me. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now