cjconstantine Posted March 14, 2006 Posted March 14, 2006 Ok, here's what I'm trying to do (script is programmed as OnEvent)... I have a GuiCtrlCreateInput designated for the definition of a hotkey, what I want to do is when the user presses the keys they want to use for the hotkey it will appear in the control (ie ... user presses CTRL+A as the hotkey, then CTRL+A appears in the control). But ... if they just press CTRL or ALT or SHIFT and release the field is cleared out. And no other input is allowed after a "non-special" key is pressed (ie, with the above example ... after the A key is pressed no other key will appear in the input box. Yep ... I am still a noob. But I do realize this may creep into "that which must not be named area" (keylogger). I've looked at the _IsPressed UDF, but I can't wrap my head around how to use it in this case.
nfwu Posted March 15, 2006 Posted March 15, 2006 (edited) I use this UDF to allow the user to select a hotkey: (Simpler to code) expandcollapse popup;=============================================================================== ; ; Function Name: _SetHotKeyDialog() ; Description: Opens a dialog for people to choose a hotkey. In format: modifier+key ; Parameter(s): $hotkeytext - Purpourse of hotkey which you ask the user to set ; $oldhotkeymod - "Default" hotkey mod. ; "alt", "ctrl", "winkey", "alt+ctrl", "alt+winkey", "ctrl+winkey", "alt+ctrl+winkey" - All lowercase! ; $oldhotkeykey - "Defalut" hotkey key. a-z(lowercase), 0-9, {F1}-{F12} (excluding {F5}), all {} keys except for {CTRLBREAK} ; Requirement(s): AutoIt ; Return Value(s): On Success - Returns array ; $return[0] is modifier (eg. "alt+ctrl") ; $return[1] is key (eg. "s") ; $return[2] is hotkey in send format (eg. "!^s"). ; On Failure - Returns nothing and sets @ERROR = 1 ; Author(s): nfwu (aka TechDude) me@techdudeonline.tk ; ;=============================================================================== Func _SetHotKeyDialog($hotkeytext, $oldhotkeymod, $oldhotkeykey) #include <GuiConstants.au3> ;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 ;If not IsDeclared('WS_OVERLAPPEDWINDOW') Then Global Const $WS_OVERLAPPEDWINDOW = 0x00CF0000 ;if Not IsDeclared('WS_VISIBLE') Then Global Const $WS_VISIBLE = 0x10000000 If Not IsDeclared('TDS_SFKD_GUI') Then $TDS_SFKD_GUI = GUICreate("MyGUI", 195, 150, (@DesktopWidth - 195) / 2, (@DesktopHeight - 135) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $TDS_SFKD_Label1 = GUICtrlCreateLabel("You are modifying the HotKey for:", 10, 0, 180, 20) $TDS_SFKD_ComboMod = GUICtrlCreateCombo("", 80, 50, 100, 21) $TDS_SFKD_ComboKey = GUICtrlCreateCombo("", 80, 100, 100, 21) $TDS_SFKD_Label2 = GUICtrlCreateLabel("AND", 120, 80, 50, 20) $TDS_SFKD_Label3 = GUICtrlCreateLabel("Modifier:", 30, 50, 40, 20) $TDS_SFKD_Label4 = GUICtrlCreateLabel("Key:", 50, 100, 20, 20) $TDS_SFKD_Label5 = GUICtrlCreateLabel("<purpose of hotkey>", 10, 20, 180, 20) $TDS_SFKD_button = GUICtrlCreateButton( "OK", 10, 130, 180, 20) Dim $TDS_SFKD_RETURN_VALUE[3] EndIf GUICtrlSetData($TDS_SFKD_Label5, $hotkeytext) GUICtrlSetData($TDS_SFKD_ComboMod, "alt|ctrl|winkey|alt+ctrl|alt+winkey|ctrl+winkey|alt+ctrl+winkey", $oldhotkeymod) GUICtrlSetData($TDS_SFKD_ComboKey, "{F1}|{F2}|{F3}|{F4}|{F6}|{F7}|{F8}|{F9}|{F10}|{F11}|{F12}|{SPACE}|{ENTER}|{BACKSPACE}|{DELETE}|{ UP}|{DOWN}|{LEFT}|{RIGHT}|{HOME}|{END}|{ESC}|{INSERT}|{PGUP}|{PGDN}|{TAB}|{PRINTSCREEN}|{PAUSE}|{CAP SLOCK}|1|2|3|4|5|6|7|8|9|0|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|w|x|y|z", $oldhotkeykey) GUISetState(@SW_SHOW, $TDS_SFKD_GUI) While 1 $msgs = GUIGetMsg(1) $msg = $msgs[0] If $msgs[1] == $TDS_SFKD_GUI Then Select Case $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $TDS_SFKD_GUI) SetError(1) Return Case $msg = $TDS_SFKD_button $TDS_SFKD_RETURN_VALUE[0] = GUICtrlRead($TDS_SFKD_ComboMod) $TDS_SFKD_RETURN_VALUE[1] = GUICtrlRead($TDS_SFKD_ComboKey) Select Case $TDS_SFKD_RETURN_VALUE[0] == "ctrl" $TDS_SFKD_RETURN_VALUE[2] = "^" Case $TDS_SFKD_RETURN_VALUE[0] == "alt" $TDS_SFKD_RETURN_VALUE[2] = "!" Case $TDS_SFKD_RETURN_VALUE[0] == "winkey" $TDS_SFKD_RETURN_VALUE[2] = "#" Case $TDS_SFKD_RETURN_VALUE[0] == "alt+ctrl" $TDS_SFKD_RETURN_VALUE[2] = "!^" Case $TDS_SFKD_RETURN_VALUE[0] == "alt+winkey" $TDS_SFKD_RETURN_VALUE[2] = "!#" Case $TDS_SFKD_RETURN_VALUE[0] == "ctrl+winkey" $TDS_SFKD_RETURN_VALUE[2] = "^#" Case $TDS_SFKD_RETURN_VALUE[0] == "alt+ctrl+winkey" $TDS_SFKD_RETURN_VALUE[2] = "!^#" EndSelect $TDS_SFKD_RETURN_VALUE[2] = $TDS_SFKD_RETURN_VALUE[2] & $TDS_SFKD_RETURN_VALUE[1] Return $TDS_SFKD_RETURN_VALUE Case Else ;;; EndSelect EndIf WEnd EndFunc;==>_SetHotKeyDialog There is a way to do what you have requested, but it requires too much code if you do it the "traditional" way [well, i'm off to try doing it the "traditional" way!] #) Edited March 15, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
nfwu Posted March 15, 2006 Posted March 15, 2006 (edited) #include <GuiConstants.au3> Func _GetHotKey() Global $__G__OK = False GLOBAL $__G__HOTKEY = '' Local $keys = StringSplit( '|{F1}|{F2}|{F3}|{F4}|{F6}|{F7}|{F8}|{F9}|{F10}|{F11}|{F12}|{SPACE}|{ENTER}|{BACKSPACE}|{DELETE}| {UP}|{DOWN}|{LEFT}|{RIGHT}|{HOME}|{END}|{ESC}|{INSERT}|{PGUP}|{PGDN}|{TAB}|{PRINTSCREEN}|{PAUSE}|{CA PSLOCK}|1|2|3|4|5|6|7|8|9|0|a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|w|x|y|z', '|') For $j = 2 to $keys[0] HotKeySet('!'&$keys[$j], '_RespondToHotKey') Next local $hotkeyget = GuiCreate('', 127, 64,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GuiCtrlCreateLabel('Please press a hotkey', 10, 10, 110, 20) Local $Button_2 = GuiCtrlCreateButton("Cancel", 30, 30, 60, 20) GuiSetState() While $__G__OK == False $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_2 ExitLoop EndSelect WEnd GUIDelete($hotkeyget) For $j = 2 to $keys[0] HotKeySet("!"&$keys[$j]) Next Return $__G__HOTKEY EndFunc Func _RespondToHotKey() $__G__OK = True $__G__HOTKEY = @HotKeyPressed EndFunc HOW TO USE: Call _GetHotKey. The HotKey will be the hotkey that is returned from this function. KNOWN PROBLEM: only accepts hotkeys that are Alt+{SOMETHING} format. There is a limit to the number of hotkeys you can set, i think. #) EDIT: fed up of trying to get rid of that &39; and &37;... they won;t go away no matter what i do! Edited March 15, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
cjconstantine Posted March 15, 2006 Author Posted March 15, 2006 Thank you both for the code! Both use GuiGetMsg so I don't think they'll work with OnEvent ... but it did give me a nudge in a different direction.
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