Jump to content

Recommended Posts

Posted

Hello all,

is possible to create a script that sets the key to be pressed from information taken from an ini file?

AutoIt.au3

HotKeySet( IniRead("file.ini", "Section", "Key", "Hotkey"), "Function" )

file.ini

[Section]
Key=F5

So the result would be:

HotKeySet( "F5", "Function" )
Posted (edited)

Hi,

Yes, but you need to use valid key combinations according to the function HotKeySet (explained for the function Send in the helpfile), so it would be {F5} here.

Br, FireFox.

Edited by FireFox
Posted (edited)

Thanks, worked perfectly as I wanted.

File.ini

[Section1]
Key1=Alt+F1
Key2=Ctrl+F1

Func KeySets($pSection, $pKey, $pFunc)
    #comments-start
        ! = Alt
        + = Shift
        ^ = Ctrl
    #comments-end
    If StringInStr( IniRead($arq, $pSection, $pKey, ""), "+" ) > 0 Then
        $cKey = StringLeft( IniRead($arq, $pSection, $pKey, ""), StringInStr( IniRead($arq, $pSection, $pKey, ""), "+" )-1 )
        Switch $cKey
            Case "Ctrl"
                $cReturn = "^{"& StringRight ( IniRead($arq, $pSection, $pKey, ""), StringInStr( IniRead($arq, $pSection, $pKey, ""), "+" )-2 ) &"}"
            Case "Alt"
                $cReturn = "!{"& StringRight ( IniRead($arq, $pSection, $pKey, ""), StringInStr( IniRead($arq, $pSection, $pKey, ""), "+" )-2 ) &"}"

            Case "Shift"
                $cReturn = "+{"& StringRight ( IniRead($arq, $pSection, $pKey, ""), StringInStr( IniRead($arq, $pSection, $pKey, ""), "+" )-2 ) &"}"
        EndSwitch
    Else
        $cReturn = "{"&IniRead($arq, $pSection, $pKey, "")&"}"
    EndIf
    HotKeySet( $cReturn, $pFunc)
EndFunc

KeySets("Section1", "Key1", "FuncA") -=> HotKeySet("!{F1}", "FuncA")
KeySets("Section1", "Key2", "FuncB") -=> HotKeySet("^{F1}", "FuncB")
Edited by Darkbeo

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
×
×
  • Create New...