therks Posted March 8, 2007 Share Posted March 8, 2007 (edited) Bugfix (2007-03-26): Now recognizes either keycode in default key param for the keys with 2 different codes (bs, backspace; del, delete; ins, insert; esc, escape). Bugfix (2007-03-23): Thanks to raca here for pointing this out. This made the function work improperly when giving it a preset key like _ChooseHotKey('#^{bs}'). Note also, I realized this function doesn't work properly for some keys with two different codes (ie: {bs} and {backspace}, only works for {bs} key). So I'm going to try and fix this right now, but I wanted to get this bug fix up first. Major Update (2007-03-17): I added in a couple extra functions, and changed the structure of the code to be a bit faster (no more huge arrays). I also changed the name of the include file altogether, since it's more than just the ChooseHotKey function now. I've created a few programs with AutoIt where I allowed the end user to customize a hotkey or two, and I got fed up with either explaining how hotkeys work ("# is Win, + is Shift, {space} is space", etc) and letting users enter them manually, or creating a bunch of controls on the program's window. So I finally decided to code up a function that I could easily add in to any script, and figured I'd share it on here cus some other people might have a use for it. Include header: AutoIt Version: 3.2.2.0 Language: English Description: Functions that assist with hotkeys. Author: Rob Saunders (admin@therks.com) Function list: _ChooseHotKey _HotKeyToString _StringToHotKey Function headers: expandcollapse popupDescription: _ChooseHotKey Parameter(s): $sDefaultKey - Default key to be selected when dialog window appears (in valid HotKeySet format). Default blank (no preselected hotkey). $iReturnType - Specifies return value. See return value comments below. Default False. $sTitle - Title for dialog window. Default "Choose HotKey" $iLeft - Left position of dialog window. Default keyword or -1 to center. $iTop - Top position of dialog window. Default keyword or -1 to center. $iStyle - Style to apply to dialog window. Default keyword or -1 sets to BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU). $iExStyle - Extended style to apply to dialog window. Default keyword or -1 sets to $WS_EX_TOOLwindow. $hParent - Handle to parent window for dialog window to be child of. $bAutoDisable - Set to True to auto disable/re-enable/re-activate parent window when dialog window appears/closes (does not apply if invalid $hParent set). Return Value: If user hits OK and $iReturnType = 0: Returns valid HotKeySet format string (ex: "#z", "^+{enter}", "#^!+{numpadadd}", etc.) If user hits OK and $iReturnType = 1: Returns array with following info: $array[0] = Keyboard key selected. ("c" or "{space}" etc) $array[1] = 1 if Windows key checked or 0 if not $array[2] = 1 if Ctrl key checked or 0 if not $array[3] = 1 if Alt key checked or 0 if not $array[4] = 1 if Shift key checked or 0 if not $array[5] = Valid HotKeySet format string (same as returntype 1) * Note: If the chosen hotkey is available (not already in use), @extended is set to 1, otherwise 0. If user hits Cancel: Returns "" and sets @error to 1 and @extended to 0 User CallTip: _ChooseHotKey( [ $sDefaultKey = '' [, $iReturnType = 0 [, $sTitle = 'Choose HotKey' [, $iLeft = Default [, $iTop = Default [, $iStyle = Default [, $iExStyle = Default [, $hParent = 0 [, $bAutoDisable = True ] ] ] ] ] ] ] ] ] ) Show a dialog for a user to choose a HotKey for a HotKeySet function. (required: <_HotKey.au3>) =============================================================================== Description: _HotKeyToString Parameter(s): $sKeyIn - Key combo in valid HotKeySet format (ie: ^!a). Return Value: Conversion of input hotkey to string representation. User CallTip: _HotKeyToString( $sKeyIn ) Convert hotkey to string. (required: <_HotKey.au3>) Examples: In: #^c Out: Win+Ctrl+C In: !{numpadmult} Out: Alt+NumPad Multiply =============================================================================== Description: _StringToHotKey Parameter(s): $sKeyIn - Key combo in string representation (ie: Ctrl+Alt+A). Return Value: Conversion of string representation to valid hotkey. User CallTip: _StringToHotKey( $sKeyIn ) Convert string to hotkey. (required: <_HotKey.au3>) Examples: In: Win+Ctrl+C Out: #^c In: Ctrl+Pause/Break Out: ^{pause} Notes: This function is not necessarily very useful because it relies on the input to coordinate with the $___HOTKEY_S_KEYLIST_NAMES global variable (ie: some people might write their hotkeys like "Control+Alt+Break", and this function relies on it looking like "Ctrl+Alt+Pause/Break"). I provided it mainly for converting the return from _HotKeyToString back to a valid hotkey format if needed. Let me know if you find any problems!_HotKey.au3 Edited March 26, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
theguy0000 Posted March 8, 2007 Share Posted March 8, 2007 did you test it? The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
therks Posted March 8, 2007 Author Share Posted March 8, 2007 Yeah. Why, is there something wrong with it? My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
theguy0000 Posted March 8, 2007 Share Posted March 8, 2007 (edited) i try running this: CODEexpandcollapse popup$key = _ChooseHotKey () MsgBox (0, "You chose...", $key) #cs =============================================================================== AutoIt Version: 3.2.2.0 Description: _ChooseHotKey Parameter(s): $sDefaultKey - Default key to be selected when dialog window appears (in valid HotKeySet format). Default blank (no preselected hotkey). $iReturnType - Specifies return value. See return value comments below. Default False. $sTitle - Title for dialog window. Default "Choose HotKey" $iLeft - Left position of dialog window. Default keyword or -1 to center. $iTop - Top position of dialog window. Default keyword or -1 to center. $iStyle - Style to apply to dialog window. Default keyword or -1 sets to BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU). $iExStyle - Extended style to apply to dialog window. Default keyword or -1 sets to $WS_EX_TOOLwindow. $hParent - Handle to parent window for dialog window to be child of. $bAutoDisable - Set to True to auto disable/re-enable/re-activate parent window when dialog window appears/closes (does not apply if invalid $hParent set). Return Value: If user hits OK and $iReturnType = 0: Returns valid HotKeySet format string (ex: "#z", "^+{enter}", "#^!+{numpadadd}", etc.) If user hits OK and $iReturnType = 1: Returns array with following info: $array[0] = Keyboard key selected. ("c" or "{space}" etc) $array[1] = 1 if Windows key checked or 0 if not $array[2] = 1 if Ctrl key checked or 0 if not $array[3] = 1 if Alt key checked or 0 if not $array[4] = 1 if Shift key checked or 0 if not $array[5] = Valid HotKeySet format string (same as returntype 1) * Note: If the chosen hotkey is available (not already in use), @extended is set to 1, otherwise 0. If user hits Cancel: Returns "" and sets @error to 1 and @extended to 0 User CallTip: _ChooseHotKey( [ $sDefaultKey = '' [, $iReturnType = 0 [, $sTitle = 'Choose HotKey' [, $iLeft = Default [, $iTop = Default [, $iStyle = Default [, $iExStyle = Default [, $hParent = 0 [, $bAutoDisable = True ] ] ] ] ] ] ] ] ] ) Show a dialog for a user to choose a HotKey for a HotKeySet function. (required: <_ChooseHotKey.au3>) Author: Rob Saunders (admin@therks.com) =============================================================================== #ce Func _ChooseHotKey($sDefaultKey = '', $iReturnType = 0, $sTitle = 'Choose HotKey', $iLeft = Default, $iTop = Default, $iStyle = Default, $iExStyle = Default, $hParent = 0, $bAutoDisable = True) Do Local Const $iDEFBUTTONSTYLE = 0x00000001 ; $BS_DEFPUSHBUTTON Local Const $iLABELSTYLE = 0x00000200 ; $SS_CENTERIMAGE Local Const $iCOMBOSTYLE = 0x00200003 ; BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL) Local $aGM, $vReturn = '', $iError = 0, $iExtended = 0 Local $sModKeys = '#^!+' Local $sListKeys = 'a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|1|2|3|4|5|6|7|8|9|0|`|-|=|\|[|]|;|''|,|.|/|' & _ '{space}|{enter}|{esc}|{bs}|{del}|{up}|{down}|{left}|{right}|{home}|{end}|{ins}|{pgup}|{pgdn}|' & _ '{f1}|{f2}|{f3}|{f4}|{f5}|{f6}|{f7}|{f8}|{f9}|{f10}|{f11}|{f12}|{tab}|{printscreen}|{numlock}|{capslock}|{scrolllock}|{pause}|' & _ '{numpad0}|{numpad1}|{numpad2}|{numpad3}|{numpad4}|{numpad5}|{numpad6}|{numpad7}|{numpad8}|{numpad9}|' & _ '{numpadmult}|{numpadadd}|{numpadsub}|{numpaddiv}|{numpaddot}|{numpadenter}|{appskey}|{sleep}|' & _ '!|{browser_back}|{browser_forward}|{browser_refresh}|{browser_stop}|{browser_search}|{browser_favorites}|{browser_home}|' & _ '{volume_mute}|{volume_down}|{volume_up}|{media_next}|{media_prev}|{media_stop}|{media_play_pause}|' & _ '{launch_media}|{launch_mail}|{launch_app1}|{launch_app2}' Local $sListNames = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|1|2|3|4|5|6|7|8|9|0|`|-|=|\|[|]|;|''|,|.|/|' & _ 'Space|Enter|Escape|Backspace|Delete|Up|Down|Left|Right|Home|End|Insert|Page Up|Page Down|' & _ 'F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|Tab|PrintScreen|NumLock|CapsLock|ScrollLock|Pause/Break|' & _ 'NumPad 0|NumPad 1|NumPad 2|NumPad 3|NumPad 4|NumPad 5|NumPad 6|NumPad 7|NumPad 8|NumPad 9|' & _ 'NumPad Multiply|NumPad Add|NumPad Subtract|NumPad Divide|NumPad Period|NumPad Enter|Windows Application key|Computer SLEEP key|' & _ '[ Win2k/XP specific keys ]|Browser: Back|Browser: Forward|Browser: Refresh|Browser: Stop|Browser: Search|Browser: Favorites|Browser: Web/Home|' & _ 'Volume: Mute|Volume: Down|Volume: Up|Media: Next|Media: Previous|Media: Stop|Media: Play/pause|' & _ 'Launch: Media player|Launch: E-mail program|Launch: User App1|Launch: User App2' Local $aListKeys = StringSplit($sListKeys, '|') Local $aListNames = StringSplit($sListNames, '|') Local $aKeyInfo[6] = [ $sDefaultKey, 0, 0, 0, 0 ] If $aListKeys[0] <> $aListNames[0] Then $iError = 99 ExitLoop EndIf Local $i_GUIOnEventMode = Opt('GUIOnEventMode', 0) Local $i_GUICoordMode = Opt('GUICoordMode', 1) If $sDefaultKey <> '' Then For $i = 1 to 4 $aKeyInfo[0] = StringReplace($aKeyInfo[0], StringMid($sModKeys, $i, 1), '') If @extended Then $aKeyInfo[$i] = 1 Next EndIf If $iStyle = Default OR $iStyle = -1 Then $iStyle = 0x80C80000 ; BitOr($WS_CAPTION, $WS_POPUP, $WS_SYSMENU) EndIf If $iExStyle = Default OR $iExStyle = -1 Then $iExStyle = 0x00000080 ; $WS_EX_TOOLWINDOW EndIf If $bAutoDisable AND IsHWnd($hParent) Then WinSetState($hParent, '', @SW_DISABLE) EndIf Local $gui_Hotkey = GUICreate($sTitle, 200, 103, $iLeft, $iTop, $iStyle, $iExStyle, $hParent) GUICtrlCreateLabel('Modifier keys:', 5, 0, 190, 20, $iLABELSTYLE) Local $a_KeyControls[5] $a_KeyControls[1] = GuiCtrlCreateCheckbox('&Win', 5, 20, 40, 20) $a_KeyControls[2] = GuiCtrlCreateCheckbox('&Ctrl', 50, 20, 40, 20) $a_KeyControls[3] = GuiCtrlCreateCheckbox('&Alt', 95, 20, 30, 20) $a_KeyControls[4] = GuiCtrlCreateCheckbox('&Shift', 135, 20, 40, 20) For $i = 1 to 4 If $aKeyInfo[$i] Then GUICtrlSetState($a_KeyControls[$i], 1) ; $GUI_CHECKED EndIf Next GUICtrlCreateLabel('&Key:', 5, 45, 25, 20, $iLABELSTYLE) $a_KeyControls[0] = GUICtrlCreateCombo('', 35, 45, 160, 200, $iCOMBOSTYLE) GUICtrlSetData(-1, $sListNames, 'Space') If $aKeyInfo[0] <> '' Then For $i = 1 to $aListKeys[0] If $aListKeys[$i] = $aKeyInfo[0] Then GUICtrlSetData(-1, $aListNames[$i]) ExitLoop EndIf Next EndIf Local $bt_OK = GUICtrlCreateButton('OK', 55, 75, 65, 23, $iDEFBUTTONSTYLE) Local $bt_Cancel = GUICtrlCreateButton('Cancel', 130, 75, 65, 23) GUISetState(@SW_SHOW, $gui_Hotkey) ControlFocus($gui_Hotkey, '', $a_KeyControls[0]) While 1 $aGM = GUIGetMsg(1) If $aGM[1] = $gui_Hotkey Then Switch $aGM[0] Case $bt_OK $aKeyInfo[0] = GUICtrlRead($a_KeyControls[0]) For $i = 1 to 4 If GUICtrlRead($a_KeyControls[$i]) = 1 Then $vReturn &= StringMid($sModKeys, $i, 1) $aKeyInfo[$i] = 1 EndIf Next For $i = 1 to $aListNames[0] If $aListNames[$i] = $aKeyInfo[0] Then $vReturn &= $aListKeys[$i] $aKeyInfo[0] = $aListKeys[$i] ExitLoop EndIf Next $iExtended = HotKeySet($vReturn, '_ChooseHotKey') HotKeySet($vReturn) If $iReturnType Then $aKeyInfo[5] = $vReturn $vReturn = $aKeyInfo EndIf $iError = 0 ExitLoop Case $bt_Cancel, -3 ; $GUI_EVENT_CLOSE = -3 $iError = 1 ExitLoop EndSwitch EndIf WEND GUIDelete($gui_Hotkey) Until True Opt('GUIOnEventMode', $i_GUIOnEventMode) Opt('GUICoordMode', $i_GUICoordMode) If $bAutoDisable AND IsHWnd($hParent) Then WinSetState($hParent, '', @SW_ENABLE) WinActivate($hParent) EndIf Return SetError($iError, $iExtended, $vReturn) EndFunc ;==>_ChooseHotKey and i get this: >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Documents and Settings\xxxxxxxxx\My Documents\AutoIt\choose_hotkey.au3" /autoit3dir "C:\Program Files\AutoIt3\beta" /UserParams +> Starting AutoIt3Wrapper v.1.7.3 >Running AU3Check (1.54.6.0) params: from:C:\Program Files\AutoIt3\beta C:\Documents and Settings\xxxxxxxxx\My Documents\AutoIt\choose_hotkey.au3(153,55) : ERROR: _ChooseHotKey() called with wrong number of args. $iExtended = HotKeySet($vReturn, '_ChooseHotKey') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\xxxxxxxxx\My Documents\AutoIt\choose_hotkey.au3(44,194) : REF: definition of _ChooseHotKey(). Func _ChooseHotKey($sDefaultKey = '', $iReturnType = 0, $sTitle = 'Choose HotKey', $iLeft = Default, $iTop = Default, $iStyle = Default, $iExStyle = Default, $hParent = 0, $bAutoDisable = True) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Documents and Settings\xxxxxxxxx\My Documents\AutoIt\choose_hotkey.au3 - 1 error(s), 0 warning(s) !>AU3Check ended.rc:2 >Exit code: 0 Time: 1.728 Edited March 8, 2007 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
therks Posted March 8, 2007 Author Share Posted March 8, 2007 (edited) Oh I see. Hmm. I don't use au3check, so I didn't see that warning... er... error?Hmm... I see, that's because when a hotkey is chosen, it uses hotkeyset just to get the availability of the hotkey. I figured on just using the _ChooseHotKey func in the hotkeyset because it's only set for a brief moment and would not actually be used, so wouldn't need to worry about the parameters not passing. I guess I will just make a dummy function to hotkeyset to.Thanks for pointing this out. I will fix this right now and go to bed (so long as my battery doesn't die!).*Edit: Forgot an important "not" in original post. K, going to sleep now (7am yeesh, stayed up too late). Edited March 8, 2007 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
theguy0000 Posted March 8, 2007 Share Posted March 8, 2007 aha, I see, if I click "continue anyway" (and ignore the errors) it works just fine. still might wanna fix that, though... The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
Apzo Posted March 8, 2007 Share Posted March 8, 2007 (edited) Very clean and useful, Saunders ! 5 stars for this one, that's the kind of include I love This code works : #include "_ChooseHotKey.au3" $key = _ChooseHotKey () MsgBox (0, "You chose...", $key) Apzo. Edited March 8, 2007 by Apzo All the pop3 functions.Rsync your files on your USB key (or anywhere else) Link to comment Share on other sites More sharing options...
therks Posted March 8, 2007 Author Share Posted March 8, 2007 Actually, I just realized another bug in the code, also to do with hotkey availability check. I was unsetting the hotkey whether it got set or not, and so if the hotkey was unavailable because it was already set somewhere in that same script it would unset it. I'm going to update for that fix right now. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted March 8, 2007 Share Posted March 8, 2007 Actually, I just realized another bug in the code, also to do with hotkey availability check. I was unsetting the hotkey whether it got set or not, and so if the hotkey was unavailable because it was already set somewhere in that same script it would unset it. I'm going to update for that fix right now.awesome nice script.. Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted March 9, 2007 Share Posted March 9, 2007 (edited) hey, i modified itfor user controls, see example. [edit] better example.. expandcollapse popup#include <GUIConstants.au3> $Form1 = GUICreate("Hotkey GUI example", 571, 328, 192, 125) $Combo1 = GUICtrlCreateCombo("", 347, 49, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open Notepad:", 48, 53, 77, 17) $Checkbox1 = GUICtrlCreateCheckbox("Win", 134, 49, 45, 20) $Checkbox2 = GUICtrlCreateCheckbox("Ctrl", 187, 48, 41, 21) GUICtrlSetState(-1,1) $Checkbox3 = GUICtrlCreateCheckbox("Alt", 239, 48, 41, 21) $Checkbox4 = GUICtrlCreateCheckbox("Shift", 295, 51, 41, 21) $Combo2 = GUICtrlCreateCombo("", 348, 77, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open This:", 49, 81, 77, 17) $Checkbox5 = GUICtrlCreateCheckbox("Win", 135, 77, 45, 20) $Checkbox6 = GUICtrlCreateCheckbox("Ctrl", 188, 76, 41, 21) $Checkbox7 = GUICtrlCreateCheckbox("Alt", 240, 76, 41, 21) $Checkbox8 = GUICtrlCreateCheckbox("Shift", 296, 79, 41, 21) $Combo3 = GUICtrlCreateCombo("", 347, 117, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open wgfgh:", 48, 121, 77, 17) $Checkbox9 = GUICtrlCreateCheckbox("Win", 134, 117, 45, 20) $Checkbox10 = GUICtrlCreateCheckbox("Ctrl", 187, 116, 41, 21) $Checkbox11 = GUICtrlCreateCheckbox("Alt", 239, 116, 41, 21) $Checkbox12 = GUICtrlCreateCheckbox("Shift", 295, 119, 41, 21) $Combo4 = GUICtrlCreateCombo("", 343, 152, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open That:", 44, 156, 77, 17) $Checkbox13 = GUICtrlCreateCheckbox("Win", 130, 152, 45, 20) $Checkbox14 = GUICtrlCreateCheckbox("Ctrl", 183, 151, 41, 21) $Checkbox15 = GUICtrlCreateCheckbox("Alt", 235, 151, 41, 21) $Checkbox16 = GUICtrlCreateCheckbox("Shift", 291, 154, 41, 21) $Combo5 = GUICtrlCreateCombo("", 342, 186, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open Those:", 43, 190, 77, 17) $Checkbox17 = GUICtrlCreateCheckbox("Win", 129, 186, 45, 20) $Checkbox18 = GUICtrlCreateCheckbox("Ctrl", 182, 185, 41, 21) $Checkbox19 = GUICtrlCreateCheckbox("Alt", 234, 185, 41, 21) $Checkbox20 = GUICtrlCreateCheckbox("Shift", 290, 188, 41, 21) $Combo6 = GUICtrlCreateCombo("", 341, 223, 156, 21,BitOr($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlCreateLabel("Open Close:", 42, 227, 77, 17) $Checkbox21 = GUICtrlCreateCheckbox("Win", 128, 223, 45, 20) $Checkbox22 = GUICtrlCreateCheckbox("Ctrl", 181, 222, 41, 21) $Checkbox23 = GUICtrlCreateCheckbox("Alt", 233, 222, 41, 21) $Checkbox24 = GUICtrlCreateCheckbox("Shift", 289, 225, 41, 21) $Group1 = GUICtrlCreateGroup("Hotkeys", 29, 14, 501, 267) GUICtrlCreateGroup("", -99, -99, 1, 1) $Button1 = GUICtrlCreateButton("Save", 172, 291, 106, 27) $Button2 = GUICtrlCreateButton("Cancel", 297, 290, 106, 27) For $x = 1 to 6 GUICtrlSetData(Eval('Combo'&$x),_HotKeyLoadkeys(), Chr(64 + $x)) Next GUISetState(@SW_SHOW) While 1 $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE,$Button2 ExitLoop Case $Button1 ;~ For $x = 1 to 6 ;~ MsgBox (0, "You chose...", _HotKeyLoadkeys(1, Eval('Combo'&$x)) ) ;~ Next MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo1, $Checkbox1,$Checkbox2,$Checkbox3,$Checkbox4) ) MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo2, $Checkbox5,$Checkbox6,$Checkbox7,$Checkbox8) ) MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo3, $Checkbox10,$Checkbox6,$Checkbox11,$Checkbox12) ) MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo4, $Checkbox13,$Checkbox14,$Checkbox15,$Checkbox16) ) MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo5, $Checkbox17,$Checkbox18,$Checkbox19,$Checkbox20) ) MsgBox (0, "You chose...", _HotKeyLoadkeys(1, $Combo6, $Checkbox21,$Checkbox22,$Checkbox23,$Checkbox23) ) Case Else ;;;;;;; EndSwitch WEnd Exit Func _HotKeyLoadkeys($sSetKeys = 0, $sDefaultKey = '', $sWin = -1, $sCtrl = -1, $sAlt = -1, $sShift = -1) Local $vReturn Local $sModKeys = '#^!+' Local $sListKeys = 'a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|1|2|3|4|5|6|7|8|9|0|`|-|=|\|[|]|;|''|,|.|/|' & _ '{space}|{enter}|{esc}|{bs}|{del}|{up}|{down}|{left}|{right}|{home}|{end}|{ins}|{pgup}|{pgdn}|' & _ '{f1}|{f2}|{f3}|{f4}|{f5}|{f6}|{f7}|{f8}|{f9}|{f10}|{f11}|{f12}|{tab}|{printscreen}|{numlock}|{capslock}|{scrolllock}|{pause}|' & _ '{numpad0}|{numpad1}|{numpad2}|{numpad3}|{numpad4}|{numpad5}|{numpad6}|{numpad7}|{numpad8}|{numpad9}|' & _ '{numpadmult}|{numpadadd}|{numpadsub}|{numpaddiv}|{numpaddot}|{numpadenter}|{appskey}|{sleep}|' & _ '!|{browser_back}|{browser_forward}|{browser_refresh}|{browser_stop}|{browser_search}|{browser_favorites}|{browser_home}|' & _ '{volume_mute}|{volume_down}|{volume_up}|{media_next}|{media_prev}|{media_stop}|{media_play_pause}|' & _ '{launch_media}|{launch_mail}|{launch_app1}|{launch_app2}' Local $sListNames = 'A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|1|2|3|4|5|6|7|8|9|0|`|-|=|\|[|]|;|''|,|.|/|' & _ 'Space|Enter|Escape|Backspace|Delete|Up|Down|Left|Right|Home|End|Insert|Page Up|Page Down|' & _ 'F1|F2|F3|F4|F5|F6|F7|F8|F9|F10|F11|F12|Tab|PrintScreen|NumLock|CapsLock|ScrollLock|Pause/Break|' & _ 'NumPad 0|NumPad 1|NumPad 2|NumPad 3|NumPad 4|NumPad 5|NumPad 6|NumPad 7|NumPad 8|NumPad 9|' & _ 'NumPad Multiply|NumPad Add|NumPad Subtract|NumPad Divide|NumPad Period|NumPad Enter|Windows Application key|Computer SLEEP key|' & _ '[ Win2k/XP specific keys ]|Browser: Back|Browser: Forward|Browser: Refresh|Browser: Stop|Browser: Search|Browser: Favorites|Browser: Web/Home|' & _ 'Volume: Mute|Volume: Down|Volume: Up|Media: Next|Media: Previous|Media: Stop|Media: Play/pause|' & _ 'Launch: Media player|Launch: E-mail program|Launch: User App1|Launch: User App2' If $sSetKeys = 0 Then $vReturn = $sListNames Else Local $aKeyInfo[5] $aKeyInfo[0] = GUICtrlRead($sDefaultKey) Local $a_KeyControls[6] = [5, $sWin, $sCtrl, $sAlt, $sShift] Local $aListKeys = StringSplit($sListKeys, '|') Local $aListNames = StringSplit($sListNames, '|') For $i = 1 to 4 If GUICtrlRead($a_KeyControls[$i]) = 1 Then $vReturn &= StringMid($sModKeys, $i, 1) $aKeyInfo[$i] = 1 EndIf Next For $i = 1 to $aListNames[0] If $aListNames[$i] = $aKeyInfo[0] Then $vReturn &= $aListKeys[$i] $aKeyInfo[0] = $aListKeys[$i] ExitLoop EndIf Next EndIf Return $vReturn EndFunc Edited March 9, 2007 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
therks Posted March 9, 2007 Author Share Posted March 9, 2007 Thanks guys! I've got a bunch of stuff that I've written with AutoIt but never got around to sharing, so I'm glad you like this, hopefully you'll like some of my others . I'm going to try and post here in example scripts more often. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
raca Posted March 17, 2007 Share Posted March 17, 2007 Great program! I was just knocking my head around making a dialog to choose a hotkey because i used a input box... and i can't really catch the keys the user press... when i decided to search the forum i found this great program, thanks man. Also, can i use this code to realese a public program? (it's going to be open source) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 17, 2007 Moderators Share Posted March 17, 2007 Nice work Saunders, I do something similar in my apps that I let the end-user choose what hotkey(s) they are going to use for their convenience, it also helps when another window has already set the same hotkey, the end-user can assign a different one. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
therks Posted March 17, 2007 Author Share Posted March 17, 2007 Great program!...Also, can i use this code to realese a public program? (it's going to be open source)Thanks, and go for it, enjoy!Nice work Saunders, I do something similar in my apps that I let the end-user choose what hotkey(s) they are going to use for their convenience, it also helps when another window has already set the same hotkey, the end-user can assign a different one.Yeah, that's why I added in the return in @extended. I haven't run into the problem too much myself yet, but I'm sure I will eventually.On another note, I've been working on this a bit and changed up the include a bit. I've just called it _HotKey.au3 and included a couple extra functions, plus optimized the key lookup (no more arrays). I'll update the first post with the new include. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
smashly Posted March 18, 2007 Share Posted March 18, 2007 (edited) Thank you for a great function Saunders. But could you give an example of the @extended return of 0 when a hotkey is already used? I've already set a hotkey prior to calling _ChooseHotKey, I try setting the same hotkey that's already set. I try using @ extended and it returns 1. So I put it down I'm not using the @extended correctly. Cheers Edited March 18, 2007 by smashly Link to comment Share on other sites More sharing options...
raca Posted March 23, 2007 Share Posted March 23, 2007 Bug at this line: Local $sLookupKey = ___HotKeyInc_INTERNAL_LOOKUPKEY($aKeyInfo[0]) Change to this: Local $sLookupKey = ___HotKeyInc_INTERNAL_LOOKUPKEY($aKeyInfo[0], True) Link to comment Share on other sites More sharing options...
smashly Posted March 23, 2007 Share Posted March 23, 2007 (edited) Thank You raca , nice find. Now I can use this function for what I was after. Cheers Edited March 23, 2007 by smashly Link to comment Share on other sites More sharing options...
therks Posted March 23, 2007 Author Share Posted March 23, 2007 Thank you for a great function Saunders. But could you give an example of the @extended return of 0 when a hotkey is already used? I've already set a hotkey prior to calling _ChooseHotKey, I try setting the same hotkey that's already set. I try using @ extended and it returns 1. So I put it down I'm not using the @extended correctly. Cheers I use it something like this... #include <_HotKey.au3> Do _ChooseHotKey('#r') If Not @error Then If Not @extended Then MsgBox(16,'Error','That hotkey is in use by another application, please choose another') Else ExitLoop EndIf Else ExitLoop EndIf Until False @raca: Thanks for figuring that out. I can't believe I missed it. Updated first post with that bug fix. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
therks Posted March 26, 2007 Author Share Posted March 26, 2007 Yay, another bug fix. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
smashly Posted March 27, 2007 Share Posted March 27, 2007 (edited) Thank You for the example and answer to my question Saunders, it's appreciated. Your function seems to be nice and short for what it does and I hope to use it in some of my future projects / hobbies Cheers Edited March 27, 2007 by smashly 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