Jump to content
blqk

Set short keys thru GUI

Recommended Posts

blqk

Hello all,

I have a little scripts that uses 

HotKeySet("{ESC}", "Action") , to go and execute the code in function "Action". Now I want to create a simple GUI with two boxes, the one will just contain the word "Action" and in the other the user will set the shortkey(like Alt+c, for example) and a "OK" button which when pressed will set the new shortkey combination in HotkeySet(). I have some idea how to create the gui and the buttons, but I am not sure how to do the rest. Any help will be appreciated.

Share this post


Link to post
Share on other sites
Starstar

For every action you need a function for example......

func Action1()
..............
endfunc

Therefore it will be better that create a GUICtrlCreateCombo() instead of GUICtrlCreateInput() for receiving an action. From this we can reduce chances of wrong input.

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
KaFu
Starstar
#include <GUIConstantsEx.au3>
#include <Misc.au3>

$hGUI = GUICreate("Test", 200, 100)
$cLabel = GUICtrlCreateLabel("Action", 10, 10, 50, 30)
$cInput = GUICtrlCreateInput("", 100, 10, 80, 20)
$cButton = GUICtrlCreateButton("Set HotKey", 100, 50, 80, 30)
$hButton = GUICtrlCreateButton("Test Last key", 10, 50, 80, 30)
GUISetState(@SW_SHOW)

Global $send

While 1
    If _IsPressed(11) Then
     GUICtrlSetData($cInput,"^")
    ElseIf  _IsPressed(12) Then
    GUICtrlSetData($cInput,"!")
    ElseIf  _IsPressed(10) Then
    GUICtrlSetData($cInput,"+")
    EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $cKeys = GUICtrlRead($cInput)
            If StringLen($cKeys) = 0 Then
                MsgBox(0,"","You must Enter a Key Before This")
            Else
                $cKeys = GUICtrlRead($cInput)
            IniWrite(@DesktopDir&"\keys.ini","Keys","1st",$cKeys)
            MsgBox(0,"","Hot keys set")
            Exit
            EndIf
        Case $hButton
            If FileExists(@DesktopDir&"\keys.ini") Then
            $gKeys = IniReadSection(@DesktopDir&"\keys.ini","Keys")
            HotKeySet($gKeys[1][1],"Action")
            ControlSetText("","",$cInput,$gKeys[1][1])
            MsgBox(0,"","Are you Remember What was your last key?")
            Else
            MsgBox(0,"","You have not yet set any Hotkey")
            EndIf
    EndSwitch

WEnd

Func Action()
    MsgBox(0,"","Action Performs With This key: "&$gKeys[1][1])
    EndFunc

Try this one.....

[Edit::]

A fish for you..............

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

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

×