ryanbogadi Posted September 6, 2005 Share Posted September 6, 2005 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 More sharing options...
seandisanti Posted September 6, 2005 Share Posted September 6, 2005 (edited) 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 September 6, 2005 by cameronsdad Link to comment Share on other sites More sharing options...
ryanbogadi Posted September 6, 2005 Author Share Posted September 6, 2005 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 More sharing options...
seandisanti Posted September 6, 2005 Share Posted September 6, 2005 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 More sharing options...
CodeMaster Rapture Posted September 7, 2005 Share Posted September 7, 2005 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 More sharing options...
LxP Posted September 7, 2005 Share Posted September 7, 2005 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; andre-enable it. Link to comment Share on other sites More sharing options...
ryanbogadi Posted September 7, 2005 Author Share Posted September 7, 2005 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now