Jump to content
RobOtter

Parsing Hotkey string?

Recommended Posts

RobOtter

Hi,

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
ViciousXUSMC

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
RobOtter
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
BrewManNH

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
JohnOne

Here is a quick filthy example

GUICreate("")

$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")

GUISetState()

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

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
BetaLeaf

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.

PortableApps.com 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: https://github.com/BetaLeaf

Share this post


Link to post
Share on other sites
ViciousXUSMC
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)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

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

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

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

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ExitLoop
    EndSwitch
WEnd

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

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

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

$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
    Sleep(10)
WEnd

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

 

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

    • 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
      Hello.
      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: 
       
      FTP_Screen.zip
      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.15.5.0.3960)
          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"
       
       
       
       
       
×