Ices Posted May 25, 2009 Posted May 25, 2009 (edited) I'm looking for a way to set hotkeys in other scripts with a GUI script. Other than creating an input box and having the user type in !G for alt G etc etc, I'm drawing a blank. is there a way to make a hotkey binder? I appreciate any help. Thanks in Advance, Ices Edited May 25, 2009 by Ices
martin Posted May 25, 2009 Posted May 25, 2009 I'm looking for a way to set hotkeys in other scripts with a GUI script. Other than creating an input box and having the user type in !G for alt G etc etc, I'm drawing a blank. is there a way to make a hotkey binder? I appreciate any help.Thanks in Advance,IcesYou could have a combo box headed "primary key""F1" to "F10"," a" to "z" and three (or more) check boxes in a group "modifiers"shiftALtCtr Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
smashly Posted May 26, 2009 Posted May 26, 2009 Hi, You could use a keyboard hook to get the registered keypress or use the getasync key.. I had a play with a hook method and allowing for 1 modifier key and a primary key or just a primary key on it's own.expandcollapse popup#include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include <StaticConstants.au3> #include <WinAPI.au3> Global $Modifier[7][3] = [[6, ""],["SHIFT","A0", "+"],["SHIFT","A1","+"],["CONTROL","A2","^"],["CONTROL","A3","^"],["ALT","A4","!"],["ALT","A5","!"]] Global $Primary[95][2] = [[94,""],["{BACKSPACE}","08"],["{TAB}","09"],["{ENTER}","0D"],["{PAUSE}","13"],["{CAPSLOCK}","14"], _ ["{ESCAPE}","1B"],["{SPACE}","20"],["{PGUP}","21"],["{PGDN}","22"],["{END}","23"],["{HOME}","24"], _ ["{LEFT}","25"],["{UP}","26"],["{RIGHT}","27"],["{DOWN}","28"],["{PRINTSCREEN}","2C"],["{INSERT}","2D"], _ ["{DELETE}","2E"],["0","30"],["1","31"],["2","32"],["3","33"],["4","34"],["5","35"],["6","36"],["7","37"], _ ["8","38"],["9","39"],["A","41"],["B","42"],["C","43"],["D","44"],["E","45"],["F","46"],["G","47"],["H","48"], _ ["I","49"],["J","4A"],["K","4B"],["L","4C"],["M","4D"],["N","4E"],["O","4F"],["P","50"],["Q","51"],["R","52"], _ ["S","53"],["T","54"],["U","55"],["V","56"],["W","57"],["X","58"],["Y","59"],["Z","5A"],["{NUMPAD0}","60"], _ ["{NUMPAD1}","61"],["{NUMPAD2}","62"],["{NUMPAD3}","63"],["{NUMPAD4}","64"],["{NUMPAD5}","65"],["{NUMPAD6}","66"], _ ["{NUMPAD7}","67"],["{NUMPAD8}","68"],["{NUMPAD9}","69"],["{NUMPADMULT}","6A"],["{NUMPADADD}","6B"],["{NUMPADSUB}","6D"], _ ["{NUMPADDOT}","6E"],["{NUMPADDIV}","6F"],["{F1}","70"],["{F2}","71"],["{F3}","72"],["{F4}","73"],["{F5}","74"], _ ["{F6}","75"],["{F7}","76"],["{F8}","77"],["{F9}","78"],["{F10}","79"],["{F11}","7A"],["{F12}","7B"], _ ["{NUMLOCK}","90"],["{SCROLLLOCK}","91"],[";","BA"],["=","BB"],[",","BC"],["-","BD"],[".","BE"],["/","BF"], _ ["`","C0"],["[","DB"],["\","DC"],["]","DD"],["'","DE"]] Global $hGui, $Input1, $Input2,$hHookKeyboard, $pStub_KeyProc Global $LastCID = 0, $Hook = 0, $Hotkeys $hGui = GUICreate("Set hotkeys to exit this window", 500, 70, -1, -1, $WS_CAPTION, $WS_EX_TOPMOST) $Info1 = GUICtrlCreateLabel('HotKeySet("', 5, 25, 145, 30) GUICtrlSetFont(-1, 18) GUICtrlCreateGroup("Modifier Key", 140, 10, 120, 50) $Input1 = GUICtrlCreateLabel("", 150, 30, 100, 20, BitOR($SS_SUNKEN, $SS_CENTER)) GUICtrlSetTip(-1, "Click here to set a Modiier key.") GUICtrlSetFont(-1, 11, 700) GUICtrlCreateGroup("Primary Key", 270, 10, 120, 50) $Input2 = GUICtrlCreateLabel("", 280, 30, 100, 20, BitOR($SS_SUNKEN, $SS_CENTER)) GUICtrlSetTip(-1, "Click here to set a Primary key.") GUICtrlSetFont(-1, 11, 700) $Info2 = GUICtrlCreateLabel('", "Quit")', 400, 25, 145, 30) GUICtrlSetFont(-1, 18) GUISetState(@SW_SHOW, $hGui) While 1 $msg = GUIGetMsg() Switch $msg Case $Input1, $Input2 RegisterHook($msg) Case Else If $Hook <> "" Then UnRegisterHook() EndSwitch WEnd Func RegisterHook($CurCID) If $LastCID <> $CurCID And $LastCID <> 0 Then GUICtrlSetBkColor($LastCID, Default) $LastCID = $CurCID GUICtrlSetBkColor($LastCID, 0xFFFFFF) GUICtrlSetData($LastCID, "") Return Else $LastCID = $CurCID GUICtrlSetBkColor($LastCID, 0xFFFFFF) GUICtrlSetData($LastCID, "") $pStub_KeyProc = DllCallbackRegister("_KeyProc", "int", "int;ptr;ptr") $hHookKeyboard = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($pStub_KeyProc), _WinAPI_GetModuleHandle(0), 0) EndIf EndFunc Func UnRegisterHook() GUICtrlSetData($LastCID, $Hook) GUICtrlSetBkColor($LastCID, Default) DllCallbackFree($pStub_KeyProc) _WinAPI_UnhookWindowsHookEx($hHookKeyboard) $pStub_KeyProc = 0 $hHookKeyboard = 0 $Hook = "" $LastCID = 0 Local $M, $P $M = GetModifierKey(GUICtrlRead($Input1)) $P = StringLower(GUICtrlRead($Input2)) If $M <> "" And $P <> "" Then If $Hotkeys <> "" Then HotKeySet($Hotkeys) $Hotkeys = $M & $P HotKeySet($Hotkeys, "Quit") ElseIf $M = "" And $P <> "" Then If $Hotkeys <> "" Then HotKeySet($Hotkeys) $Hotkeys = $P HotKeySet($Hotkeys, "Quit") EndIf EndFunc Func GetModifierKey($sKey) For $i = 1 To $Modifier[0][0] If $sKey = $Modifier[$i][0] Then Return $Modifier[$i][2] Next Return 0 EndFunc Func _KeyProc($nCode, $wParam, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam) Local $KBDLLHOOKSTRUCT = DllStructCreate('ushort wVk;ushort wScan;dword dwFlags;dword time;ulong_ptr dwExtraInfo', $lParam) Local $vkCode = DllStructGetData($KBDLLHOOKSTRUCT, "wVK") Switch $wParam Case $WM_KEYDOWN, $WM_SYSKEYDOWN Switch $LastCID Case $Input1 For $i = 1 To $Modifier[0][0] If $vkCode = "0x" & $Modifier[$i][1] Then $Hook = $Modifier[$i][0] Return -1 EndIf Next Case $Input2 For $i = 1 To $Primary[0][0] If $vkCode = "0x" & $Primary[$i][1] Then $Hook = $Primary[$i][0] Return -1 EndIf Next EndSwitch EndSwitch Return _WinAPI_CallNextHookEx($hHookKeyboard, $nCode, $wParam, $lParam) EndFunc Func Quit() If $pStub_KeyProc <> 0 And $hHookKeyboard <> 0 Then DllCallbackFree($pStub_KeyProc) _WinAPI_UnhookWindowsHookEx($hHookKeyboard) EndIf Exit EndFunc
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