Jump to content

Parsing Hotkey string?

Recommended Posts



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 autoitscript.com 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.

My GitHub Page: https://github.com/BetaLeaf

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

    • Blois
      By Blois
      Hi Guis,
      I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below:
      #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <GUIConstantsEx.au3> HotKeySet("^{TAB}", "_TabRight") HotKeySet("^+{TAB}", "_TabLeft") $gui = GUICreate("test",450, 300) $Tab1 = GUICtrlCreateTab(20, 24, 425, 201) $TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1") $lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50) GUICtrlSetColor(-1, 0x0000FF) GUICtrlCreateTabItem("") $TabSheet2 = GUICtrlCreateTabItem(" ") $TabSheet3 = GUICtrlCreateTabItem(" ") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _TabRight() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Func _TabLeft() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Exit  
      can you help me?
    • argumentum
      By argumentum
      AutoIt Machine Code Algorithm Collection
      By Ward, November 11, 2010 in AutoIt Example Scripts 
      Posted November 11, 2010 (edited) I have already published a lot of AutoIt UDF about algorithm, but all of them only support 32 bits or so called X86 system. Recently I got a computer with Windows 7 64 bits, so I finally added X64 support to most of my old projects. Besides, I also added some new. For example, some compression algorithm and SHA3 Candidates.
      Following are the algorithms list:
      Checksum   CRC16   CRC32   ADLER32 Compression   FastLZ   LZF   LZMA   LZMAT   MiniLZO   QuickLZ Encode   Base64   ARC4   XXTEA   DES   AES Hash   Checksums (CRC16/CRC32/ADLER32)   MD2   MD4   MD5   SHA1   SHA2 (SHA224/256/384/512)   SHA3 Candidates     BLAKE     BMW (Blue Midnight Wish)     CUBEHASH     ECHO     SHABAL     SKEIN Some points to mention:
      All of the subroutines have one or more examples to demonstrate the usage. Since the function and usage of subroutine are easy to understand. A complete subroutines and parameters list are unavailability now. Sorry for my lazy. All of the subroutines here invoked by Lazycat's method (through CallWindowProc API). My MemoryDLL UDF is not necessary this time. Although MemoryFuncCall (part of MemoryDLL) is still good, but inevitably, it is slower than CallWindowProc. Some subroutines have the same name with my old machine code version UDF. But for some reason, I rearrange the position of the parameters. Please not mix up. If you notice, yes, checksums are duplicated. But they receive different parameters. One is the old style, and another use the same interface as other hashes. Choose what you like, but don't use them in the same time. Some algorithm already supported by the standard UDF "Encryption.au3". But I still provide them, because some system lack of the full support of Windows Crypt Library. If you are looking for only one hash algorithm, for example, used in encryption, I suggested "SHABAL_TINY.au3". Although it is a bit slower then SHABAL, but it is smaller, and it supports different size of output (from 32 to 512 bits).
    • guner7
      By guner7
      Hi everyone,
      I would like to share a simple snippet where I use for my hotkey script.
      I was searching for a solution whereby pressing a same key, I could have different outcome according to the way the key is being pressed.
      1) Double tap/press fast (like double click the mouse) - outcome A
      2) Long press or HOLD for awhile (2-4 sec) - outcome B
      #Include <Timers.au3> Global $interval_timer, $counter HotKeySet("{F10}", "_terminate") While 1 Sleep(10) WEnd Func _terminate() Local $itv_timer $itv_timer = _Timer_Diff($interval_timer) $interval_timer = _Timer_Init() ;ConsoleWrite($itv_timer & @CRLF) ;to review the timer difference so I can decide the range to capture double tap sequence If $itv_timer > 100 And $itv_timer < 250 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","double tap detected") Elseif $counter >= 25 Then $counter = 0 $interval_timer = _Timer_Init() MsgBox("","","long press detected") ElseIf $itv_timer < 50 Then $counter = $counter + 1 ConsoleWrite($counter & @CRLF) Else $counter = 0 EndIf EndFunc The trick here is to collect and use the frequency of the hotkey is called, and the time difference between each time the hotkey is being called.
      My coding style is not efficient and can be such a mess most of the time, any suggestion or better coding are welcome.
      I hope you find this one helpful.
    • Ascer
      By Ascer
      A couple week ago i've started learning API Interface for different websites. In this fact sometimes you have to encode your "photo" or "document.body" to send request.
      Functions to encode and decode Base64 was already created by others. Unfortunately i have troubles with running it on Windows R 2008, also speed was terrible.
      I try to find alternative way to code data. 
      I've read about Microsoft "XMLDOM" and created a one simple function to Encode / Decode data to base64binary, base64url
      Thanks for Ghads on Wordpress i coverted a part of his lines from VBscript to AutoIT
      ;============================================================================================================================== ; Function: base64($vCode [, $bEncode = True [, $bUrl = False]]) ; ; Description: Decode or Encode $vData using Microsoft.XMLDOM to Base64Binary or Base64Url. ; IMPORTANT! Encoded base64url is without @LF after 72 lines. Some websites may require this. ; ; Parameter(s): $vData - string or integer | Data to encode or decode. ; $bEncode - boolean | True - encode, False - decode. ; $bUrl - boolean | True - output is will decoded or encoded using base64url shema. ; ; Return Value(s): On Success - Returns output data ; On Failure - Returns 1 - Failed to create object. ; ; Author (s): (Ghads on Wordpress.com), Ascer ;=============================================================================================================================== Func base64($vCode, $bEncode = True, $bUrl = False) Local $oDM = ObjCreate("Microsoft.XMLDOM") If Not IsObj($oDM) Then Return SetError(1, 0, 1) Local $oEL = $oDM.createElement("Tmp") $oEL.DataType = "bin.base64" If $bEncode then $oEL.NodeTypedValue = Binary($vCode) If Not $bUrl Then Return $oEL.Text Return StringReplace(StringReplace(StringReplace($oEL.Text, "+", "-"),"/", "_"), @LF, "") Else If $bUrl Then $vCode = StringReplace(StringReplace($vCode, "-", "+"), "_", "/") $oEL.Text = $vCode Return $oEL.NodeTypedValue EndIf EndFunc ;==>base64  
    • 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: https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm ; $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