fry128 Posted March 11, 2010 Share Posted March 11, 2010 Title isnt too clear, so let me elaborate. I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in. I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function"). I've been trying to get this all day. Link to comment Share on other sites More sharing options...
Steveiwonder Posted March 11, 2010 Share Posted March 11, 2010 HotKeySet("^.", "_SetHotKey") ; Calls function to set new hotkey $key = "k"; Default Key to exit script While 1 Sleep(100) WEnd Func _SetHotkey() GUICreate("SetKey", 120, 80, -1, -1) $key = GUICtrlCreateInput($key, 10, 5, 40) $setKeyBtn = GUICtrlCreateButton("Set Key", 10, 30) GUISetState() ; display gui While 1 $msg = GUIGetMsg() If $msg = $setKeyBtn Then HotKeySet(GUICtrlRead($key), "_exit") ; redefine hotkey ConsoleWrite(GUICtrlRead($key) & @CRLF) GUIDelete() ExitLoop EndIf WEnd EndFunc ;function called when you press the user defined hotkey. Func _exit() Exit EndFunc That will work, if you want the user to be able to press CTRL+G (example) and then that convert to "^G" then you will need a little more code. Anyway, that should start you off. They call me MrRegExpMan Link to comment Share on other sites More sharing options...
MilesAhead Posted March 11, 2010 Share Posted March 11, 2010 Title isnt too clear, so let me elaborate.I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in.I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function").I've been trying to get this all day.I took another approach and made a reusable function to let the user select hotkey modifier and main key from drop down lists. Once I got it perfected I use it in all my AutoIt3 hotkey utilities.I have a similar dialog for selecting the background color if Glass is enabled on the system.Check out the screen shot. My Freeware Page Link to comment Share on other sites More sharing options...
MilesAhead Posted March 11, 2010 Share Posted March 11, 2010 Title isnt too clear, so let me elaborate.I want to create a button that allows a customizable hotkey to call a function. I know about hotkeyset("key", "function") but thats not what I'm interested in.I want to make the hotkey itself a variable, like inputting a keystroke (variable) and pressing an "ok" button and that would make whatever key I pressed my new hotkey. Kind of like a hotkeyset("(variable)", "function").I've been trying to get this all day.I took another approach and made a reusable function to let the user select hotkey modifier and main key from drop down lists. Once I got it perfected I use it in all my AutoIt3 hotkey utilities.I have a similar dialog for selecting the background color if Glass is enabled on the system.Check out the screen shot.For the main key I use the AutoIt3 text as it's self-explanatory "{Home}" "{End}" "{Pause}"for the modifier keys I use "Alt" "Control" "Shift" "WinKey" "ControlAlt" etc.I just use a Select case to put "!" in the modifier key variable if the user selects "Alt" or "+!" for "ShiftAlt" etc... The hotkey variable itself I just concatenate the modifier with the main hotkey, with a little bit of error checking. It works out pretty well. Plus I just save the modifier and main parts of the current hotkey to .ini file. My Freeware Page Link to comment Share on other sites More sharing options...
Mat Posted March 11, 2010 Share Posted March 11, 2010 There is a windows control called a hotkey control that is used for exactly this. UDF: GUIHotkey.au3Mat AutoIt Project Listing 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