Jump to content

hotkeys customizable by user


gcue
 Share

Recommended Posts

i am trying to allow the user to create his/her own hotkeys not sure what's wrong as the syntax coincides with my hardcoded hotkeys (which work)

i get a syntax error

Dim $AccelKeys[$number_of_hotkeys][$number_of_hotkeys] = $hotkeys_final

Dim $hotkeys

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

If Not @error Then
For $x = 1 To UBound($hotkey_settings) - 1
    $hotkeys &= '["' & $hotkey_settings[$x][1] & '", $' & $hotkey_settings[$x][0] & '],'

    $hotkey_settings[$x][0] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")
Next

$hotkeys_final = "[" & StringTrimRight($hotkeys, 1) & "]"

$number_of_hotkeys = UBound($hotkey_settings) - 1

Dim $AccelKeys[$number_of_hotkeys][$number_of_hotkeys] = $hotkeys_final
EndIf

hehe i havent gotten to the point where i can test this part (bc the part above crashes) but i dont think it looks right

Func Hotkeys()

    Switch @GUI_CtrlId
    
    for $x = 1 to UBound($hotkey_settings)-1
        Case $hotkey_settings[$x][0]
            $hotkey_settings[$x][0] & "()"
    Next        
        
    EndSwitch

EndFunc   ;==>Hotkeys

would this even be possible?

thank you in advance.

Edited by gcue
Link to comment
Share on other sites

i am trying to allow the user to create his/her own hotkeys not sure what's wrong as the syntax coincides with my hardcoded hotkeys (which work)

i get a syntax error

Dim $hotkeys

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

If Not @error Then
For $x = 1 To UBound($hotkey_settings) - 1
    $hotkeys &= '["' & $hotkey_settings[$x][1] & '", & $hotkey_settings[$x][0] & '],'

    $hotkey_settings[$x][0] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")
Next

$hotkeys_final = "[" & StringTrimRight($hotkeys, 1) & "]"

$number_of_hotkeys = UBound($hotkey_settings) - 1

Dim $AccelKeys[$number_of_hotkeys][$number_of_hotkeys] = $hotkeys_final
EndIf

Getting married cannot have done you any good at all :(

Try replacing that with something like this (not tested)

Global $hotkey_settings

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

$number_of_hotkeys = UBound($hotkey_settings)

;convert variable name to ID, assuming the name is something like "$Button1"
for $n = 0 to UBound($hotkey_settings) - 1
    ;if no dollar sign at start then remove stringtrimleft
    $hotkey_settings[$n][1] = eval(StringTrimLeft($hotkey_settings[$n][1],1))
Next

Func Hotkeys()

    Switch @GUI_CtrlId
    
    for $x = 1 to UBound($hotkey_settings)-1
        Case $hotkey_settings[$x][0]
            $hotkey_settings[$x][0] & "()"
    Next        
        
    EndSwitch

EndFunc ;==>Hotkeys

I don't understand what you are trying to do there.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

haha ya i think so - sleep deprived mostly. and overeating (dang she cooks good!)

the last part i was trying to assign the function name to the hotkey... to keep things simple i was trying to make $hotkey_settings[$x][0] the name of the function..

how would i assign a function?

thanks for the help!

Link to comment
Share on other sites

haha ya i think so - sleep deprived mostly. and overeating (dang she cooks good!)

the last part i was trying to assign the function name to the hotkey... to keep things simple i was trying to make $hotkey_settings[$x][0] the name of the function..

how would i assign a function?

thanks for the help!

Oh I see. So to help me a bit more, what would a line in your ini file look like in the HOTKEYS section?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

so add_pc and del_pc would be the control id names and also the names of the functions

^a (ctrl a) and ^D (ctrl+shift+d) are the hotkeys

=)

I think this is what you need.

Global $hotkey_settings
;del_pc=^D for ex
$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

Global $number_of_hotkeys = UBound($hotkey_settings)

Dim $hotkeys[$number_of_hotkeys][2]
;convert variable name to ID
For $n = 0 To $number_of_hotkeys - 1
    $hotkeys[$n][0] = $hotkey_settings[$n][1]
    $hotkeys[$n][1] = Eval($hotkey_settings[$n][0])
Next
GUISetAccelerators($hotkeys)

Func Hotkeys()
    Local $x

    For $x = 0 To $number_of_hotkeys - 1
    If @GUI_CtrlId = $hotkeys[$x][1] Then
    Call($hotkey_settings[$x][0])
    ExitLoop
    EndIf
    Next

EndFunc ;==>Hotkeys
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

i did an arraydisplay and its only showing a value for the first value in the array...[guisetaccelerators needs a 2d array =)]

i think the second value in the array is supposed to be the controlid? so i think i have to create a dummy control id first

also it can serve as a pointer to the hotkeys function itself (which will resolve what the function each hotkey runs)..

Global $hotkey_settings

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

Global $number_of_hotkeys = UBound($hotkey_settings)

Dim $hotkeys[$number_of_hotkeys][2]
;convert variable name to ID
For $n = 1 To $number_of_hotkeys - 1
    $hotkey_settings[$n][0] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")

    $hotkeys[$n][0] = $hotkey_settings[$n][1]
    $hotkeys[$n][1] = $hotkey_settings[$n][0]
Next
_ArrayDisplay($hotkeys)
GUISetAccelerators($hotkeys)

Func Hotkeys()
    Local $x

    For $x = 0 To $number_of_hotkeys - 1
        If @GUI_CtrlId = $hotkeys[$x][1] Then
            Call($hotkey_settings[$x][0])
            ExitLoop
        EndIf
    Next

EndFunc   ;==>Hotkeys

it's not reaching the hotkeys function it seems - but i think we're getting close!!!!

thank you very much for your help... any idea why it wouldnt be working?

Edited by gcue
Link to comment
Share on other sites

i did an arraydisplay and its only showing a value for the first value in the array...[guisetaccelerators needs a 2d array =)]

i think the second value in the array is supposed to be the controlid? so i think i have to create a dummy control id first

also it can serve as a pointer to the hotkeys function itself (which will resolve what the function each hotkey runs)..

Global $hotkey_settings

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

Global $number_of_hotkeys = UBound($hotkey_settings)

Dim $hotkeys[$number_of_hotkeys][2]
;convert variable name to ID
For $n = 1 To $number_of_hotkeys - 1
    $hotkey_settings[$n][0] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")

    $hotkeys[$n][0] = $hotkey_settings[$n][1]
    $hotkeys[$n][1] = $hotkey_settings[$n][0]
Next
_ArrayDisplay($hotkeys)
GUISetAccelerators($hotkeys)

Func Hotkeys()
    Local $x

    For $x = 0 To $number_of_hotkeys - 1
        If @GUI_CtrlId = $hotkeys[$x][1] Then
            Call($hotkey_settings[$x][0])
            ExitLoop
        EndIf
    Next

EndFunc ;==>Hotkeys

it's not reaching the hotkeys function it seems - but i think we're getting close!!!!

thank you very much for your help... any idea why it wouldnt be working?

I didn't ask enough questions!

I assumed you had a gui and that the names you had in the ini file were the names of the controls. If you don't have a gui then you don't want accelerators you want Hot keys. Is that correct? If so then I can show you what needs to be done.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

i do have a gui =)

i do want hotkeys this is how i currently have them working though (they are hardcoded but i am trying to allow for user customization)

$altiris_add = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$add_pc = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$editini = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$prefs = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$openlog = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$refresh = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$timetracker = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$links_remedy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$links_mist = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$help = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")
$check_updates = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, "Hotkeys")

Dim $AccelKeys[11][11] = [["^A", $altiris_add],["^a", $add_pc],["^e", $editini],["^p", $prefs],["^l", $openlog],["{f5}", $refresh],["^t", $timetracker],["^r", $links_remedy],["^m", $links_mist],["^h", $help],["^u", $check_updates]]
GUISetAccelerators($AccelKeys)

Func Hotkeys()

    Switch @GUI_CtrlId
        Case $altiris_add
            AltirisAdd_Gui()
        Case $add_pc
            Add_PC()
        Case $editini
            EditINI()
        Case $prefs
            Preferences()
        Case $openlog
            OpenLOG()
        Case $refresh
            Refresh()
        Case $timetracker
            TimeTracker_GUI()
        Case $links_remedy
            Links_Remedy()
        Case $links_mist
            Links_MIST()
        Case $help
            Help()
        Case $check_updates
            Check_Updates()
    EndSwitch

EndFunc   ;==>Hotkeys
Link to comment
Share on other sites

I think it should be lik ethis

Global $hotkey_settings

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

Global $number_of_hotkeys = UBound($hotkey_settings)

Dim $hotkeys[$number_of_hotkeys][2]
;convert variable name to ID
For $n = 1 To $number_of_hotkeys - 1
    $hotkeys[$n][1] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")

    $hotkeys[$n][0] = $hotkey_settings[$n][1]
    
Next
_ArrayDisplay($hotkeys)
GUISetAccelerators($hotkeys)

Func Hotkeys()
    Local $x

    For $x = 0 To $number_of_hotkeys - 1
    If @GUI_CtrlId = $hotkeys[$x][1] Then
    Call($hotkey_settings[$x][0])
    ExitLoop
    EndIf
    Next

EndFunc ;==>Hotkeys
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

still not working.. :(

i put in a msgbox in the hotkeys function just to see if its getting there and its not...

hmm..

This small demo works, the ini file is khs.ini and has the lines

[HOTKEYS]
add_pc=^a
del_pc=^d

the script is

#include <array.au3>
Opt("GuiOnEventMode",1)
$sINI = "hks.ini"

$gg = GUICreate("jyuguiy")
GUISetState()
Global $hotkey_settings

$hotkey_settings = IniReadSection($sINI, "HOTKEYS")

Global $number_of_hotkeys = $hotkey_settings[0][0]

Dim $hotkeys[$number_of_hotkeys][2]

For $n = 1 To $number_of_hotkeys
    $hotkeys[$n-1][1] = GUICtrlCreateDummy()
    GUICtrlSetOnEvent(-1, "Hotkeys")

    $hotkeys[$n-1][0] = $hotkey_settings[$n][1]

Next
_ArrayDisplay($hotkeys)
GUISetAccelerators($hotkeys)
while 1

    sleep(90)

WEnd

Func Hotkeys()
    Local $x
    For $x = 0 To $number_of_hotkeys - 1
    If @GUI_CtrlId = $hotkeys[$x][1] Then
    Call($hotkey_settings[$x+1][0])
    ExitLoop
    EndIf
    Next

EndFunc ;==>Hotkeys


Func add_pc()

    ConsoleWrite("called add_pc" & @CRLF)

EndFunc

Func del_pc()

    ConsoleWrite("called del_pc" & @CRLF)

EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

worked!

musta been something with the way i was doing ubound and u were using [0][0]

which still isnt clear why it wasnt working..maybe looking at it too long

but it works now!

MANY MANY MANY THANKS!!!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...