Jump to content
Sign in to follow this  
ryanbogadi

Temporarily Disable Hotkeys

Recommended Posts

ryanbogadi

Is there an easy way to temporarily disable all hotkeys set in a program. Basically, my problem is that my script relies heavily on hotkeys. And if the user happens to open another window, such as a messenger application, and try to type a message to someone, these hotkeys basically become like landmines. I have found a way to keep the hotkeys from executing their normal behavior using "if" statements. But those keys are still unusable in other applications as long as my program is still running.

I know that one solution would be to set the hotkeys to something unlikely to be pressed in any other app (such as ctrl+shift+something). But I do not want the users to be forced to press any more buttons than is absolutely necessary. If anyone knows of any way to solve my problem, I would appreciate the help.

Share this post


Link to post
Share on other sites
seandisanti

Is there an easy way to temporarily disable all hotkeys set in a program.  Basically, my problem is that my script relies heavily on hotkeys.  And if the user happens to open another window, such as a messenger application, and try to type a message to someone, these hotkeys basically become like landmines.  I have found a way to keep the hotkeys from executing their normal behavior using "if" statements.  But those keys are still unusable in other applications as long as my program is still running.

I know that one solution would be to set the hotkeys to something unlikely to be pressed in any other app (such as ctrl+shift+something).  But I do not want the users to be forced to press any more buttons than is absolutely necessary.  If anyone knows of any way to solve my problem, I would appreciate the help.

<{POST_SNAPBACK}>

the easiest way is with if statements, most likely how you're already doing. example:

HotKeySet("{PAUSE}", "RightWindow")
while 1 
    sleep(100)
WEnd

Func RightWindow()
    If WinActive("Untitled - Notepad")Then    MsgBox("0","Success","This hotkey would not have worked if you were not in notepad")
EndFunc

***edit***

or you could just unassign the hotkeys if you really want to go that way...

HotKeySet("{PAUSE}", "OtherFunc")
while 1 
    sleep(100)
    If WinActive("Untitled - Notepad") = 0 then
        HotKeySet("{PAUSE}","")
        while WinActive("Untitled - Notepad") = 0
            sleep(100)
        WEnd
        HotKeySet("{PAUSE}", "OtherFunc")
    EndIf
WEnd
Edited by cameronsdad

Share this post


Link to post
Share on other sites
ryanbogadi

Yes, that's exactly what I'm doing right now. But it still lacks one big functionality. I want to be able to use that key that I assigned as a hotkey in other applications, while mine is still running. So if my GUI is active and I press the hotkey, it executes the function I assigned it to. And if any other window is active and I press that same key, I want that key to do what it would normally do (not its hotkey function).

Share this post


Link to post
Share on other sites
seandisanti

Yes, that's exactly what I'm doing right now.  But it still lacks one big functionality.  I want to be able to use that key that I assigned as a hotkey in other applications, while mine is still running.  So if my GUI is active and I press the hotkey, it executes the function I assigned it to.  And if any other window is active and I press that same key, I want that key to do what it would normally do (not its hotkey function).

<{POST_SNAPBACK}>

i thought that may be the case... i was editing my post while you were adding this one...

Share this post


Link to post
Share on other sites
CodeMaster Rapture

I dunno if you are using a GUI or not, but you can always do this:

While 1
        If Not (WinActive("Your window's name here")) Then
                HotKeySet("{PAUSE}");remove the hotkey
                HotKeySet(Other key);remove the other hotkey
        Else
                HotKeySet("{PAUSE}","Some_Function")
                HotKetSet(Other key, "Some_other_Function")
        EndIf
        Sleep(10)
WEnd

Share this post


Link to post
Share on other sites
LxP

You could set the hotkey as normal and then in the function that is called when the key is pressed:

  • Check what the active window is.
  • If the window is my GUI, perform the necessary function.
  • If it isn't:
  • disable the hotkey;
  • send the key combination to the active window; and
  • re-enable it.

Share this post


Link to post
Share on other sites
ryanbogadi

Thanks guys. I did what you suggested and it works just fine. I didn't know that you could remove a hotkey by just not assigning a function as a parameter. Now that I know that, I can toggle them on and off depending on the active window, which is just what I wanted to do.

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  

×