Jump to content

HotKeySet woes


Recommended Posts

Hi guys, firstly, I'm new to AutoIT, and so far I love it. Never thought I'd be making scripts, but most of it's easy if you follow the help files.

My problem:

I want to make a HotKeyPress perform a function, but I want the HotKeyPress to be a variable which I decide through an input (GUICtrlCreateInput)

Is this possible? I have searched the forums but couldn't find anything relevant.

And I have another quick question. When do I need to declare my variables, and what are local and global?

#include <GUIConstants.au3>
#include <Sound.au3>
#include <Misc.au3>
_Singleton("UavTimer")

Local $keyvar
Global $Button1, $keyset, $ShowGui, $ExitTray





;UAV timer script, the GUI
GuiCreate("Dodo's UAV Timer")
    $Button1 = GUICtrlCreateButton("Set Key", 50, 100, 50, 50)
    $keyset = GUICtrlCreateInput("", 50, 10, 50, 50)
    GuiSetState(); Show GUI
    #NoTrayIcon
    Call("SwitchtoGui");Switch to GUI
    
While 1
    
;Checks GUI for input
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        Exit
        
    Case $msg = $Button1
        $keyvar = Chr(34)&GUICtrlRead($keyset)&Chr(34)
        MsgBox(0, GUICtrlRead($keyset), GUICtrlRead($keyset))
        Call("SwitchtoTray")
        TraySetToolTip ( "6v6 UAV Timer Script running")
        TrayTip ( "", "6v6 UAV Timer Script runninfg", 10)
        HotKeySet($keyvar, "Timestart")
    EndSelect
    
    
;Checks TrayIcon for input
    $msg = TrayGetMsg()
    Select
        Case $msg = $ShowGui
            Call("SwitchtoGui")
        Case $msg = $ExitTray
            Exit
    EndSelect
WEnd


; Hides GUI, and shows tray icon
Func SwitchtoTray()
    GUISetState(@SW_HIDE)
    $ShowGui = TrayCreateItem("Show")
    $ExitTray = TraycreateItem("Close")
    TraySetState(1)
    Opt("TrayMenuMode",1)
EndFunc


;Hides Tray icon, and shows GUI 
Func SwitchtoGui()
    GUISetState(@SW_SHOW)
    TraySetState(2)
EndFunc


;Counts down (In approx 1s interval) until UAV launch. Currently button to be pressed 1s after UAV destruction
Func Timestart()
    SoundPlay("four.wav", 0)
    Sleep(1000)
    SoundPlay("three.wav", 0)
    Sleep(950)
    SoundPlay("two.wav", 0)
    Sleep(950)
    SoundPlay("one.wav", 0)
    Sleep(950)
    SoundPlay("zero.wav", 0)
EndFunc

If you need more info, just ask, I'll be checking back frequently.

Regards,

Dodoextinct

Link to comment
Share on other sites

Had a shower and something to eat and figured out that if you replace a variable in the hotkeyset, you don't have to replace the quotation marks.

HotKeySet($variable, "function call")

So if

$variable becomes the letter "p", HotKeySet will act as if it was

HotKeySet("p", "function call"

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