Jump to content

Parsing Hotkey string?


Guest
 Share

Recommended Posts

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!

Link to comment
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.

Link to comment
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?

Link to comment
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

Link to comment
Share on other sites

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.

Link to comment
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)
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

 

Link to comment
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
 Share

×
×
  • Create New...