Jump to content

Temporarily Disable Hotkeys


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.

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