Parsing Hotkey string?

10 posts in this topic


is there a function or a UDF for parsing a hotkey definition string like "^a" or "+!{F1}" ?

I´d like to create a settings GUI where users are able to define their custom hotkeys for a specific function and then save it to an ini. Of course, at the next start of the program, these settings have to read and not only the HotkeySet() command needs to be fed with it but also the settings GUI.

As I do not want to present the user just the hotkey string but a rather user-friendly display (like checkboxes for the separate modifier keys and a drop down list of supported trigger keys), I need to fiddle on the saved string.

I would envision a function that takes a hotkey string and returns for example an array like this: [isCtrl][isAlt][isShift][isWin][triggerKey][isTriggerVirtual]. And of course, there needs to be a function decoding the array back to the respective string representation.


Thanks for your hints!

Share this post

Link to post
Share on other sites

You do not need any special UDF or Function for this.

All the native stuff will work just fine.

Example Idea:

Create a GUI with Checkboxes that represent Alt, Control, Shift, Etc and an Inputbox to put the letter or number (or a drop down) and another drop down to select the function.

A button to then exit the GUI loop and read the data and save to an INI

I would probably have a separate script run @ login that looks for that INI file and if it exists loads the given hotkeys and functions.

Share this post

Link to post
Share on other sites
1 hour ago, ViciousXUSMC said:

... and read the data and save to an INI

And that´s exactly the point: how do I do this? Of course, reading the current settings from the GUI controls is quite straight forward but how to do it the other way round - parsing the INI values to spread the separated data amoung the GUI controls?

Share this post

Link to post
Share on other sites

Ok, thanks! So I saved time to look no further.

Share this post

Link to post
Share on other sites

I would use the hotkey UDF found here

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

Here is a quick filthy example


$button = GUICtrlCreateButton("OK", 10, 40)
$input = GUICtrlCreateInput("", 300, 10) ;enter a letter
$combo = GUICtrlCreateCombo("", 100, 10, 100) ;select a modifier
GUICtrlSetData(-1, "CTRL|SHIFT|ALT")


While 3
    Switch GUIGetMsg()
        Case -3
        Case $button
            $modifier = ""
            Switch GUICtrlRead($combo)
                Case "CTRL"
                    $modifier = "^"
                Case "SHIFT"
                    $modifier = "+"
                Case "ALT"
                    $modifier = "!"
            $hot = $modifier & GUICtrlRead($input)
            HotKeySet($hot, thefunc)

Func thefunc()
    MsgBox(0, 0, 0)
EndFunc   ;==>thefunc


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post

Link to post
Share on other sites

See my example map.au3 and map.txt for an example on how to use a string to trigger a function like a hotkey would.


False Positive Reporter - Mass email all anti virus vendors with an attachment of your program for fast and easy whitelisting. App Creation Wizard  - A simple GUI-based Wizard for creating PortableApps.

SoundBoard - Play any song or sound you want at the press of a hotkey.

My GitHub Page:

Share this post

Link to post
Share on other sites
4 hours ago, RobOtter said:

And that´s exactly the point: how do I do this? Of course, reading the current settings from the GUI controls is quite straight forward but how to do it the other way round - parsing the INI values to spread the separated data amoung the GUI controls?

Still the same concept.  The native INIRead and INIWrite functions mixed with GUICtrlSetData and GUICtrlSetState are all you need.

This is a messy example showing how it saves the data to an INI, but when you open it reads the data from the INI.  It also Sets the Hotkey active.

You can tweak this to keep the GUI open and update the hotkey in real time, or like I said I would have 2 scripts one for setting the hotkey and a 2nd to use it.

Global $sINIFile = @ScriptDir & "\test.ini"
Global $vMyHotkey = ""
Global $sMyHotkey = ""

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test Form", 383, 149, 192, 124)
$Checkbox1 = GUICtrlCreateCheckbox("Alt", 48, 56, 50, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Ctrl", 48, 72, 50, 17)
$Checkbox3 = GUICtrlCreateCheckbox("Shift", 48, 88, 50, 17)
$Input1 = GUICtrlCreateInput("Hotkey", 104, 56, 121, 21)
$Button1 = GUICtrlCreateButton("Set!", 256, 48, 75, 57)
#EndRegion ### END Koda GUI section ###

#Region INI Update Section
If INIRead($sINIFile, "HOTKEYS", "AltKey", "UnChecked") = "Checked" Then
    GUICtrlSetState($Checkbox1, 1)
    GUICtrlSetState($Checkbox1, 4)

If INIRead($sINIFile, "HOTKEYS", "ControlKey", "UnChecked") = "Checked" Then
    GUICtrlSetState($Checkbox2, 1)
    GUICtrlSetState($Checkbox2, 4)

If INIRead($sINIFile, "HOTKEYS", "ShiftKey", "UnChecked") = "Checked" Then
    GUICtrlSetState($Checkbox3, 1)
    GUICtrlSetState($Checkbox3, 4)

GUICtrlSetData($Input1, INIRead($sINIFile, "HOTKEYS", "MainKey", "Hotkey"))
#EndRegion INI Update Section

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
        Case $Button1

If GUICtrlRead($Checkbox1) = 4 Then
    IniWrite($sINIFile, "HOTKEYS", "AltKey", "UnChecked")
    $vMyHotkey &= "!"
    $sMyHotKey &= "Alt + "
    IniWrite($sINIFile, "HOTKEYS", "AltKey", "Checked")

If GUICtrlRead($Checkbox2) = 4 Then
    IniWrite($sINIFile, "HOTKEYS", "ControlKey", "UnChecked")
    $vMyHotkey &= "^"
    $sMyHotKey &= "Ctrl + "
    IniWrite($sINIFile, "HOTKEYS", "ControlKey", "Checked")

If GUICtrlRead($Checkbox3) = 4 Then
    IniWrite($sINIFile, "HOTKEYS", "ShiftKey", "UnChecked")
    $vMyHotkey &= "+"
    $sMyHotKey &= "Shift + "
    IniWrite($sINIFile, "HOTKEYS", "ShiftKey", "Checked")

$vMyHotKey &= GUICtrlRead($Input1)
$sMyHotKey &= GUICtrlRead($Input1)
IniWrite($sINIFile, "HOTKEYS", "MainKey", GUICtrlRead($Input1))

HotKeySet($vMyHotkey, "MyFunction")

MsgBox(0, "", "Your Hotkey Has Been Set For" & @CRLF & $sMyHotKey)

While 1

Func MyFunction()
    MsgBox(0, "", "Function Triggered!")


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Xandy
      By Xandy
      Screenshot program that can upload/FTP to website/storage with hotkey.
      Features GUI to display programmable keys.

      Set the hotkeys with this function to use, and display hotkeys.
      ; hotkey_set() Parameters: ; ----------------------------------------------------------- ; $aHotkey -                The array hotkeys are stored in. This function sets the values of this array[hotkey_id][$hotkey_data] ; $dHotkey_id -             The enum for this hotkey index ; $sHotkey_description -     The label displayed to the user to represent function of hotkey ; $sHotkey_name -            The hotkey it'self.  Whatever name string you want to give the key ; $dHotkey_key -             The _IsPressed keycode ;    Keycodes AT: ; $dHotkey_shift -             Shift flag 0 or 1 Default off ; $dHotkey_ctrl -             Ctrl flag 0 or 1 Default off ; $dHotkey_alt -             Alt flag 0 or 1 Default off Func hotkey_set(ByRef $aHotkey, $dHotkey_id, $sHotkey_description, $sHotkey_name, $dHotkey_key, $dHotkey_shift = 0, $dHotkey_ctrl = 0, $dHotkey_alt = 0)     $aHotkey[$dHotkey_id][$eHotkey_data_key_description] = $sHotkey_description     $aHotkey[$dHotkey_id][$eHotkey_data_key_name] = $sHotkey_name     $aHotkey[$dHotkey_id][$eHotkey_data_key] = $dHotkey_key     $aHotkey[$dHotkey_id][$eHotkey_data_shift] = $dHotkey_shift     $aHotkey[$dHotkey_id][$eHotkey_data_ctrl] = $dHotkey_ctrl     $aHotkey[$dHotkey_id][$eHotkey_data_alt] = $dHotkey_alt EndFunc   ;==>hotkey_set ; You can set your hotkeys here ; Please visit the hotkey_set() function for parameter information hotkey_set($aHotkey, $eHotkey_screenshot_ftp, "Selected Window to FTP", "F12", "7B", 0, 1, 0); F12 hotkey_set($aHotkey, $eHotkey_screenshot_disk, "Selected Window to Disk", "S", "53", 1, 1, 1); S hotkey_set($aHotkey, $eHotkey_clipboard_send, "Send Clipboard keystrokes", "F10", "79", 1, 1, 1); F10  
      Configure settings dialog:

      Screenshot Filename and Screenshot Counter, are used to create simple unique filenames that can cycle. Copy URL to clipboard option. - For linking your screenshots. The screenshot file type is for local copy only. App always uses .JPG for FTP right now, but I could add FTP screenshot file type specification.  
      Any suggestions?  Did I break anything, what did I miss?
      Package uses TTS.au3 by Beege: 
      File includes:
         - FTP_Screen.au3
         - FTPScreen.ico
         - TTS.au3 - by Beege
    • vindicta
      By vindicta
      Hello everyone,
      I am trying to setup a GUI accelerator to close the utility as soon as esc is pressed.  It works fine with hotkey but I want to make sure that the utility only exits if its window was active when esc was pressed. My utility has 2 buttons, Backup and Restore.
      The exit function checks if the button clicked was Backup or Restore and then displays an error message accordingly.
      If pressed backup, $button = 1
      if pressed restore, $button = 2
      the value of $button is set inside backup() or restore() functions
      Opt("GUIOnEventMode", 1) Opt("GUICoordMode", 1) $Form1 = GUICreate("Form1", 419, 124, 238, 194, $WS_DLGFRAME) $B_backup = GUICtrlCreateButton("Backup", 48, 40, 145, 41) $B_restore = GUICtrlCreateButton("Restore", 224, 40, 145, 41) ;================ > HotKeySet('{ESC}', "terminate") GUICtrlSetOnEvent($B_backup, "Backup") GUICtrlSetOnEvent($B_restore, "Restore") GUISetState(@SW_SHOW) Dim $accelKey[1][2] = [["{ESC}", terminate()]] GUISetAccelerators($accelKey) While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd  
      Exit function:
      func terminate() Do     $msg = GUIGetMsg() Until $msg <> 0 While 1         If $button = 1 Then             ProcessClose("robocopy.exe")             MsgBox(16, "Abort!", "Backup Aborted!")             exit         ElseIf $button = 2 Then             ProcessClose("robocopy.exe")             MsgBox(16, "Abort!", "Restore Aborted!")             exit         Else             While 1                 For $i = 3 To 1 Step -1                     SplashTextOn("Closing Utility...", $i, 130, 54, -1, -1, 0, "Calibri", "", 900)                     Sleep(1000)                 Next                 ExitLoop             WEnd             SplashOff()             Exit Endif WEnd What am I doing wrong here? The utility closes as soon as it launches with Splash text.
    • blemas
      By blemas
      The McAfee return for AV defs per "C:\Progra~1\Common~1\McAfee\SystemCore\csscan.exe -Versions" is ...
      CommonShell Command Line Scanner Lite (VSCORE.
          Engine version: 5800.7501
          DAT version:    8450.0
          Time required:  15 milliseconds
      I want to isolate the actual DAT version as "8450.0".  There may be an easier way to get the DAT Version via other McAfee or registry methods but essentially I just want to know how to parse a string at a character or @CRLF into two separate strings for further parsing. Example:
      $string = "Name=Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
      Parse into $var1 = "Name" & $var2 = "Microsoft Windows 10 Professional |C:\windows|\Device\Harddisk0\Partition2"
      From there I'd like to parse $var2 at "|" into  $var3 = "Microsoft Windows 10 Professional" and $var4 "C:\windows|\Device\Harddisk0\Partition2"
    • Cormin
      By Cormin
      My script currently reads a text file line by line. I want it to look for this the chat message below and skip the session messages. 
      There are some garbage lines that I want it to skip over. So if a line doesnt match that format then skip it. I tried experimenting with StringRegExp but I think I'm using it wrong. Heres my code
      If StringRegExp($read, '\W\d\d\w\d\d\D.\W') = Not @error Then I was hoping that this would be able to see the open bracket, 2 digits, a colon, 2 digits,  close bracket, a space and a <. But it doesn't seem to be working.
      Eventually I want to be able to extract the username and chat message into separate strings but I haven't got that far yet.
    • ripdad
      By ripdad
      Here is  another WMIC script that parses properties from various alias classes.
      Download:  WMIC_GET.au3