Raymond Posted June 17, 2006 Share Posted June 17, 2006 (edited) Hello all!Here is my little try with AI3Opt("WinTitleMatchMode", 4)HotKeySet("{ENTER}", "_Enter")Run("cm.exe")While 1 Sleep(1000)WEndFunc _Enter() If WinActive("classname=obj_Form") Then .... ; do something ... EndIfEndFuncWhen cm.exe is in front, it works fine as I design.But if switch to other window, "ENTER" key doesn't work there. It's captured by the script, I guess. And If statment doesn't avoid that.What can I do to make Enter key do as I design when cm.exe window is active, and works as it is when other windows are active? Edited June 17, 2006 by Raymond Link to comment Share on other sites More sharing options...
BigDod Posted June 17, 2006 Share Posted June 17, 2006 Personally I would not use the enter key for a hotkey. I suggest using one of the function keys or unsetting the hotkey inside the function. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
MHz Posted June 17, 2006 Share Posted June 17, 2006 Tested with the AutoIt Helpfile. Global $hotkey, $title = "AutoIt Help" ;"classname=obj_Form" Opt("WinTitleMatchMode", 4) ;Run("cm.exe") While 1 If WinActive($title) And Not $hotkey Then $hotkey = HotKeySet("{ENTER}", "_Enter") ElseIf Not WinActive($title) And $hotkey Then HotKeySet('{ENTER}') $hotkey = 0 EndIf Sleep(1000) WEnd Func _Enter() ConsoleWrite('HotKey is On' & @LF) EndFunc Link to comment Share on other sites More sharing options...
Raymond Posted June 17, 2006 Author Share Posted June 17, 2006 (edited) Personally I would not use the enter key for a hotkey. I suggest using one of the function keys or unsetting the hotkey inside the function.Yes I can change the hotkey.But I want to know how to make HotKeySet function only apply to specific window, keeping others as they always are.I bet AI3 can do that, only I don't know yet. Edited June 17, 2006 by Raymond Link to comment Share on other sites More sharing options...
Nomad Posted June 17, 2006 Share Posted June 17, 2006 (edited) Yes I can change the hotkey. But I want to know how to make HotKeySet function only apply to specific window, keeping others as they always are. I bet AI3 can do that, only I don't know yet. If WinActive('The window you want the hotkey for') Then HotKeySet('{ENTER}', "_Enter") Else HotKeySet('{ENTER}') ; cancels hotkey EndIf Nomad Edited June 17, 2006 by Nomad Link to comment Share on other sites More sharing options...
Raymond Posted June 17, 2006 Author Share Posted June 17, 2006 If WinActive('The window you want the hotkey for') Then HotKeySet('{ENTER}', "_Enter") Else HotKeySet('{ENTER}') ; cancels hotkey EndIf Nomad Yeah! This does the trick. Thanks for your help. Only still don't get why If statement (as first floor) doesn't work as it should be. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 17, 2006 Moderators Share Posted June 17, 2006 Yeah! This does the trick.Thanks for your help.Only still don't get why If statement (as first floor) doesn't work as it should be.Because you only want the Hotkey to effect "your active" window, not the others as you stated. The hotkey is activated when the window is active and deactivated when it isn't. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Raymond Posted June 17, 2006 Author Share Posted June 17, 2006 Because you only want the Hotkey to effect "your active" window, not the others as you stated. The hotkey is activated when the window is active and deactivated when it isn't.In my first post my code is likeFunc _Enter()If WinActive("classname=obj_Form") Then....; do something...EndIfEndFuncIt seems to me not big difference from Nomad's code. But only his one works.I wonder why. Link to comment Share on other sites More sharing options...
Nomad Posted June 17, 2006 Share Posted June 17, 2006 Yeah! This does the trick.Thanks for your help. No problem, just put that into a function and call the function anytime the window changes and it will enable/disable the hotkey as needed. There are other methods you could also do, but this is probably the simplest method.As far as the hotkey functioning/not functioning... a hotkey cannot be assigned by AutoIt if it is already assigned by another program. Likewise, if the hotkey is already reserved by your script, it probably cannot be assigned by another program.There are ways around this though, as has been proven by the "full screen" mode of some games. I've started scripts before starting a full screen game, and the game automatically blocked my hotkeys and wouldn't allow them to function while in full screen. But the game hotkeys, even when the keys were the same as in my script, still functioned. So, there is a way, but I don't know it, yet. Nomad Link to comment Share on other sites More sharing options...
Raymond Posted June 17, 2006 Author Share Posted June 17, 2006 @Nomad Thanks for the explanation. 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