Sign in to follow this  
Followers 0
gcue

hotkeyset conditions

11 posts in this topic

#1 ·  Posted (edited)

i have set several hotkeys at the beginning of my script

HotKeySet("^U", "User_Add_Gui")
HotKeySet("^A", "Asset_Add_Gui")
HotKeySet("^a", "Add_PC")
HotKeySet("^e", "EditINI")
HotKeySet("^p", "Prefs")
HotKeySet("^l", "OpenLog")

but i would ONLY like to trigger them IF my GUI is the active window... i see the help that hints towards using winactive - so i thought about if @scriptname is the active window then run but i dont want these hotkeys to reference my script at ALL if the script is not the active window...

found this out because CTRL+A was not working in another application (even though it was active)

any ideas?

Edited by gcue

Share this post


Link to post
Share on other sites



ok this isnt quite working.. its opening multiple instances for some folks - any idea why?

ive tried doing a Return after the function is performed but that didnt work...

While 1
    Sleep(1)
    If _IsPressed("11") And _IsPressed("4C") And WinActive($ver) Then ;11=ctrl 4C=l
        OpenLOG()
    EndIf
Wend


Func OpenLOG()  
    If FileExists($aLOG) Then
        ShellExecute($aLOG)
        Return
    Else
        MsgBox(0, "Dashboard", "A log has not yet been generated - probably because a loggable function hasn't been performed.")
    EndIf   
EndFunc   ;==>OpenLOG

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

thanks!

how can use this without using select case?

my script is using guictrlsetonevent

Edited by gcue

Share this post


Link to post
Share on other sites

use functions its basically the exact same thing.. also it would clear up some room in your while section

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

so still use it in the while loop?

hmm not sure what the script would look like if im not using case statements..

Edited by gcue

Share this post


Link to post
Share on other sites

thanks!

how can use this without using select case?

my script is using guictrlsetonevent

Notice that when you set up the accelerator the ID of the control is passed. When the accelerator event (i.e. Ctrl-y) happens, the event for that ID is triggered. Here is the help file demo redone in event mode:
; A simple custom messagebox that uses the MessageLoop mode

#include <GUIConstantsEx.au3>

Opt("GuiOnEventMode", 1)

GUICreate("Custom Msgbox", 210, 80)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")

; Set accelerators for Ctrl+y and Ctrl+n
Dim $AccelKeys[2][2]=[["^y", $YesID], ["^n", $NoID]]
GUISetAccelerators($AccelKeys)

GUISetState() ; display the GUI

While 1
    Sleep(20)
WEnd

Func _ButtonHit()
    Switch @GUI_CtrlId
        Case $YesID
            MsgBox(0, "You clicked on", "Yes")
        Case $NoID
            MsgBox(0, "You clicked on", "No")
        Case $ExitID
            MsgBox(0, "You clicked on", "Exit")
    EndSwitch
EndFunc

Func _Quit()
    Exit
EndFunc

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

guictrlsetonevent()

it should lok like this

EXAMPLE;

$a = hotkeyset()
guictrlsetonevent($a,'_Example')

While 1
Wend

Func _example()
your data
endfunc

try that anyway it should work

Share this post


Link to post
Share on other sites

as always psalty.. u saved me

thanks!

Notice that when you set up the accelerator the ID of the control is passed. When the accelerator event (i.e. Ctrl-y) happens, the event for that ID is triggered. Here is the help file demo redone in event mode:

; A simple custom messagebox that uses the MessageLoop mode

#include <GUIConstantsEx.au3>

Opt("GuiOnEventMode", 1)

GUICreate("Custom Msgbox", 210, 80)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

GUICtrlCreateLabel("Please click a button!", 10, 10)
$YesID = GUICtrlCreateButton("Yes", 10, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")
$NoID = GUICtrlCreateButton("No", 80, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")
$ExitID = GUICtrlCreateButton("Exit", 150, 50, 50, 20)
GUICtrlSetOnEvent(-1, "_ButtonHit")

; Set accelerators for Ctrl+y and Ctrl+n
Dim $AccelKeys[2][2]=[["^y", $YesID], ["^n", $NoID]]
GUISetAccelerators($AccelKeys)

GUISetState(); display the GUI

While 1
    Sleep(20)
WEnd

Func _ButtonHit()
    Switch @GUI_CtrlId
        Case $YesID
            MsgBox(0, "You clicked on", "Yes")
        Case $NoID
            MsgBox(0, "You clicked on", "No")
        Case $ExitID
            MsgBox(0, "You clicked on", "Exit")
    EndSwitch
EndFunc

Func _Quit()
    Exit
EndFunc

:)

Share this post


Link to post
Share on other sites

Thanks, Psalty, saved me a lot of time.

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
Sign in to follow this  
Followers 0