Denik Posted May 15, 2014 Share Posted May 15, 2014 (edited) Hi, guys. The short version of my question is: Is there any way to create ASCII-code-like hotkeys? I mean, to press a special key like CTRL or ALT or SHIFT, type two or three numpad keys, then release the special key and to launch a function that way? The full story to bring you into the topic: I created a little GUI that has several "category" tabs and each tab has got several buttons. Each button launches a different program or "command". And I would like to add the option to launch these same commands through hotkeys instead of clicking buttons. So, I would like these hotkeys were something like: ctrl + category number + button number = e.g. CTRL+11 or CTRL+011 (in numpad), The challenge for me is that I can't use hotkeyset because I need to press two or three keys but not at the same time but in sequence. The same way we oftenly use to type an ASCII code (press ALT, type two or three numpad keys and release ALT), I would like to press e.g. CTRL, and to be able to type two or three numpad keys before releaseing the special key. I've tried the format {CTRLDOWN}[NUMPAD1}[NUMPAD1}{CTRLUP} but I don't get it to work with hotkeyset. Additional info: My script's GUI is dynamical. So, the number of tabs and buttons that it has got and the "commands" assigned to them are taken from an .ini file. So, since I don't know the number of controls that I need to handle nor the function associated to them, the hotkeys need to be assigned dinamically as well. That's why I thought in this "tab/button number" hotkey criteria. Any suggestion about this? Thanks for your help... Denik. Edited May 15, 2014 by Denik Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2014 Share Posted May 15, 2014 Search this forum thoroughly, there are some hotkey UDFs. Or you may try to create your own "hotkey" by using _IsPressed(). Or maybe AutoHotkey will be better choice for such specific hotkey requirement because AutoHotkey is specialized for advanced hotkeys ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
jvanegmond Posted May 23, 2014 Share Posted May 23, 2014 I saw your post in the HotStrings topic here: '?do=embed' frameborder='0' data-embedContent>>You're probably having problems with the keys not being registered or being registered incorrectly. You can add some debug info to the hotstring library to see which keys you are receiving.Take the _HotString_GUIKeyProc method and replace it with:Func _HotString_GUIKeyProc($hWnd, $Msg, $wParam, $lParam) $aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256) ConsoleWrite($aRet[0] & @CRLF) ConsoleWrite($aRet[1] & @CRLF) ConsoleWrite($aRet[2] & @CRLF) ;ConsoleWrite($aRet[3] & @CRLF) ; maybe add this one too, not sure how large this array was from memory $sKeyName = $aRet[2] If $sKeyName Then _HotString_EvaluateKey($sKeyName) EndIf Return 0 ; dont run autoit internal handler, not sure what it is, but message = handled so do nothing EndFunc github.com/jvanegmond Link to comment Share on other sites More sharing options...
Denik Posted May 24, 2014 Author Share Posted May 24, 2014 (edited) Thanks for your help @Manadar. In the meanwhile, I created my own hotkey with _isPressed this way: expandcollapse popup; In this example if you press "{Ctrl}+01" a messagebox appears #include <Misc.au3> HotKeySet("{ESC}", "Terminate") ; press Esc to exit script Func Terminate() Exit EndFunc Func RunCommand() MsgBox (0, "", "You pressed Ctrl+01") EndFunc Func MyHotKey() Local $hDLL = DllOpen("user32.dll") If _IsPressed("11", $hDLL) Then ; If Ctrl is pressed If _IsPressed("60", $hDLL) Then ; and then 0 is pressed... While _IsPressed("60", $hDLL) Sleep(100) WEnd ; ...and released While _IsPressed("11", $hDLL) ; and while Ctrl is still pressed... If _IsPressed("61", $hDLL) Then ; ...1 is pressed While _IsPressed("11", $hDLL) Sleep(100) WEnd ; once Ctrl is released... RunCommand() ; ...the RunCommand function is launched EndIf WEnd EndIf EndIf Sleep(100) DllClose($hDLL) EndFunc While 1 MyHotKey() WEnd This is my first little contribution to the forum !!! I'm not a developer so, obviously, all suggestions are welcome. Denik Edited July 18, 2014 by Denik Link to comment Share on other sites More sharing options...
jvanegmond Posted May 27, 2014 Share Posted May 27, 2014 Denik, you forgot a Sleep() in there when no keys are being pressed. The script maxes out one of my CPU cores. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Denik Posted May 31, 2014 Author Share Posted May 31, 2014 (edited) Denik, you forgot a Sleep() in there when no keys are being pressed. The script maxes out one of my CPU cores. Aha, it's true. Thanks, Manadar. I added it in the same script. Edited May 31, 2014 by Denik Link to comment Share on other sites More sharing options...
Denik Posted July 18, 2014 Author Share Posted July 18, 2014 (edited) And this would be the same script working for any "{Ctrl}+xy" combination. "X" and "y" should be any numpad key. expandcollapse popup; In this example if you press "{Ctrl}+xy" a messagebox appears. "X" and "y" should be any numpad key. #include <Misc.au3> HotKeySet("{ESC}", "Terminate") ; press Esc to exit script Func Terminate() Exit EndFunc Dim $c1, $c2 Dim $key1, $key2 Func RunCommand() MsgBox (0, "", "You pressed Ctrl+" & ($key1 - 60) & ($key2 - 60) & "") EndFunc Func MyHotKey() Local $hDLL = DllOpen("user32.dll") If _IsPressed("11", $hDLL) Then ; If Ctrl is pressed For $c1 = 60 To 69 If _IsPressed($c1, $hDLL) Then ; and then first numpad key is pressed... $key1 = $c1 While _IsPressed($c1, $hDLL) Sleep(100) WEnd ; ...and released While _IsPressed("11", $hDLL) ; and while Ctrl is still pressed... For $c2 = 60 To 69 If _IsPressed($c2, $hDLL) Then ; ...second numpad key is pressed $key2 = $c2 While _IsPressed("11", $hDLL) Sleep(100) WEnd ; once Ctrl is released... RunCommand() ; ...the RunCommand function is launched EndIf Next $c2 = 60 WEnd EndIf Next $c1 = 60 EndIf Sleep(100) DllClose($hDLL) EndFunc While 1 MyHotKey() WEnd Edited July 24, 2014 by Denik 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