Jump to content
Sign in to follow this  
Merrik

HotKeySet Question

Recommended Posts

Merrik

I have small GUI with a button and I was wondering why it is always the active window. If you open Notepad for example and write a line of text and hit ENTER it then activates my small Autoit GUI.

I'm using

"HotKeySet("{enter}", "Click_Func")

I was hoping the HotKeySet function would only be active when the GUI was the active window on the screen.

I'm hoping someone has a solution.

Share this post


Link to post
Share on other sites
Melba23

Merrik,

I was hoping the HotKeySet function would only be active when the GUI was the active window on the screen

As you have discovered, HotKeys are valid system wide. :)

But do not despair, look at GUISetAccelerators in the Help file and you will learn how to make keys which are only valid when your GUI is active. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Maffe811

I think you can do something like this:

If WinActive($GuiHamdle) then 
"HotKeySet("{enter}", "Click_Func")
Else
"HotKeySet("{enter}", "")
EndIf

Edit:

Melba beat me to it :)

Edited by Maffe811

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Melba23

Maffe811,

Your solution is also valid, but I feel it would be best to use a flag to show either if the HotKey was set or not or if the GUI was active - otherwise you will be constantly setting/resetting the HotKey as you check the GUI state. ;)

Something like this:

$fGUI_State = "Active"

If WinActive($hGUI) Then
    If $fGUI_State = "InActive" Then
        HotKeySet("{enter}", "Click_Func")
        $fGUI_State = "Active"
    EndIf
Else
    If $fGUI_State = "Active" Then
        HotKeySet("{enter}")
        $fGUI_State = "InActive"
    EndIf
EndIf

This way you only set/reset the HotKey when needed. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Maffe811

You learn stuff when you're trying to help pepole :)

I like this forum ;)


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
Merrik

Excellent! Thanks guys for the quick responses. :)

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  

×