Jump to content

Recommended Posts

Hello,

I'm trying to write a hotkey program and I know exactly how to do it but it will be hard coded and the user won't be able to edit it.

HotKeySet("{ESC}", "HotKeyPressed")
HotKeySet("^!d", "HotKeyPressed")
HotKeySet("^+x", "HotKeyPressed")

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    Switch @HotKeyPressed
        Case "{ESC}"
            Exit
        Case "^!d"
            ShellExecute("D:\Docs")
        Case "^+x"
            ShellExecute("D:\Docs\My Portables\Burner\AnyBurn\AnyBurn.exe")
    EndSwitch
EndFunc

I want the program to read a file that has hotkeys on odd lines and paths on even lines but I don't see how the program will load into itself.

Is it even possible?

Thanks.

Link to comment
Share on other sites

I know about the reading ini but let's say we read all the hotkeys and the paths that it has to execute. Now how do we generate a function on runtime and execute it? In he example above, that would be HotkeyPressed() function.

Link to comment
Share on other sites

The first way is to loop and create functions but hotkeyset needs the function created already:

$ini = @ScriptDir&"\hotkeys.ini"
Global $aHotkeys = IniReadSection($ini, "Hotkeys")
Global $i

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0], $i)
Next

While 1
    Sleep(500)
WEnd

For $i = 1 To $aHotkeys[0][0]
    Func Eval($i)&"()"
        ShellExecute($aHotkeys[$i][1])
    EndFunc
Next

The second way is to make one function with cases which is better cuz the hotkeyset already has the function ready. I just don't know how to create the cases with the array:

$ini = @ScriptDir&"\hotkeys.ini"
Global $aHotkeys = IniReadSection($ini, "Hotkeys")
Global $i

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0], "HotKeyPressed")
Next

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    Switch @HotKeyPressed
        ;Loop through array and create cases
        Case Else
            ;do nothing
    EndSwitch
EndFunc

 

Link to comment
Share on other sites

Its a dead quiet day here so I've been mucking around with it

$aHotkeys = IniReadSection(@ScriptDir & "\test.ini", "Hotkeys")

For $i = 1 To $aHotkeys[0][0]
    HotKeySet($aHotkeys[$i][0],"HotKeyPressed")
Next

While 1
    Sleep(500)
WEnd

Func HotKeyPressed()
    for $x = 1 to UBound($aHotkeys)-1
        if @HotKeyPressed = $aHotkeys[$x][0] Then Execute($aHotkeys[$x][1])
    Next
EndFunc

and make a file called test.ini in the root of the program folder with contents:
 

[Hotkeys]
+!d=ShellExecute("D:\backup")
+!x=ShellExecute("D:\repo")

this works for me

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