cal Posted July 16, 2010 Share Posted July 16, 2010 Just Cause 2 seems to be blocking Hotkeyset commands. I just want to see if anyone else has this same issue in this game. Its odd however in that it will accept a simulated keypress no problem. I can put a long sleep in the script. Start the game and it will do a keypress after the sleep is over. I can also send simulated keypresses from my mouse. But I can't define a hotkey to call a func as its being blocked. Does anyone see the same result? Link to comment Share on other sites More sharing options...
Tvern Posted July 16, 2010 Share Posted July 16, 2010 I'm no expert on how keyboard input and hotkeyset work, but the following information might be usefull in solving the problem: If you adapt your script to check the return value of hotkeyset that would atleast give you some idea as to if it registers correctly. Does the script work if the game is running, but minimized? Are your keypresses in game registered by _ispressed? Lastly and most importantly: Sharing your script will get you allot more help and usually the quality of the replies is better. Link to comment Share on other sites More sharing options...
cal Posted July 18, 2010 Author Share Posted July 18, 2010 Fair enough. I've setup a small test script. It seems the game is capturing keystrokes. The following is some simple test code. It waits 10 seconds then beeps and press the w key down. The hotkey is bound to the 5 key and it calls the func that also beeps and presses the w key down. in the game the first beep is heard and my guy starts walking forward. The func does not beep. it looks like the 5 key is trapped by the game. Outside the game with it running mimimized the script behaves as expected. Its also interesing to note that I had forgot to disable my esc as exit func here and I had pressed esc a couple times in game. But when I switched out the script was still running. I think all keys likely get trapped. Not a big deal. Other input methods are not being trapped. I can use voice commands and mouse buttons fine. I just thought it was odd. expandcollapse popup$ver = 'ver 1' #Tidy_Parameters = /Skip_EndRegion_Comment #include <misc.au3> If Not @Compiled Then Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("MouseCoordMode", 0) ;1=absolute, 0=relative Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced FileChangeDir(@ScriptDir) ; ensure this copy is the running one. $g_szVersion = "JC2 test" If WinExists($g_szVersion) Then WinClose($g_szVersion) AutoItWinSetTitle($g_szVersion) HotKeySet("{ESC}", "Terminate") Func Terminate() Exit 0 EndFunc ;==>Terminate HotKeySet('5','w_test') ;~ HotKeySet('u','w_test') ;~ HotKeySet('{f5}','w_test') sleep(10000) ; wait 10 seconds to give change to switch to game and test a non hotkey. Beep(500,500) ; beep to alert this point was reached. Send('{w down}') While 1 Sleep(30000) WEnd Exit Func w_test() Beep(500,500) Send('{w down}') EndFunc and having reread your post.... I added a triple beep in the code below. .... and the triple beep is heard in game meaning that autoit thinks it registered the hotkey correctly. expandcollapse popup$ver = 'ver 1' #Tidy_Parameters = /Skip_EndRegion_Comment #include <misc.au3> If Not @Compiled Then Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("MouseCoordMode", 0) ;1=absolute, 0=relative Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced FileChangeDir(@ScriptDir) ; ensure this copy is the running one. $g_szVersion = "JC2 test" If WinExists($g_szVersion) Then WinClose($g_szVersion) AutoItWinSetTitle($g_szVersion) HotKeySet("{ESC}", "Terminate") Func Terminate() Exit 0 EndFunc ;==>Terminate Sleep(40000) $t = HotKeySet('5','w_test') If $t = 1 Then Beep(500,500) Beep(300,500) Beep(100,500) EndIf sleep(10000) ; wait 10 seconds to give change to switch to game and test a non hotkey. Beep(500,500) ; beep to alert this point was reached. Send('{w down}') While 1 Sleep(30000) WEnd Exit Func w_test() Beep(500,500) Send('{w down}') EndFunc Link to comment Share on other sites More sharing options...
cal Posted July 18, 2010 Author Share Posted July 18, 2010 Well that was interesting. As stated above the game prevents me from setting a hotkey. But it will accept a simulated press from autoit if called via some other method. It will not accept key presses from my mouse but it will let the mouse buttons send other external commands elsewhere other then the game. So I setup the mouse to call a very basic autoit script that then holds the w key down I wanted. Net result. A mouse button toggles what I wanted. I've never had to do this before. Normally I setup an autoit script to start the game, stay resident and monitor for any hotkeys I want that can't be configured ingame. I've never had to call a second script externally like this. But it works. Now that I know the method I can do other things as well. Oddly this game will also accept key presses from my very very very old voice input program "game commander 2". I have not used that in along time. The company is gone and it was never intended for win7 but it seems to work. I was surprised that it even let me me install it, and very surprised that it still works. Link to comment Share on other sites More sharing options...
Tvern Posted July 18, 2010 Share Posted July 18, 2010 You could still try _Ispressed() to replace your hotkeys. Just put it in a while loop with a short sleep and have it check if a button is pressed continuously. Ofcoarse it could be blocked aswell, but it's worth a shot. A word of advise if you go this way: If an ispressed function returns while the button is still pressed it will be called again, unlike hotkeyset, which calls the function once per press, so you want to set up your functions to only exit once the button is released. Link to comment Share on other sites More sharing options...
cal Posted July 18, 2010 Author Share Posted July 18, 2010 A quick test to see if _ispressed is blocked or not. Looks like its not. It works fine. lol. I should have known that. I used it in my toggle func when I was further testing the mouse commands after my last post. The 2 second sleep is to take care of the possibility of returning before the key is released as you noted. Should I go with this method I'll do actual checking in the func. Thanks for the warning. I see how I could check many keys and take needed actions. Thanks, that is a good alternative to using hotkeysets in this situation. CPU utilization jumps up but does not seem to affect anything. I guess its constantly checking but mostly resting. I'm curious. the notes say "If calling this function repeatidly, should open 'user32.dll' and pass in handle." So I tryed both opening it first... $dll = DllOpen("user32.dll") _IsPressed('35',$dll) and without the open line at all and just... _IsPressed('35') to see if CPU was affected. It never seemed to matter. $ver = 'ver 1' #Tidy_Parameters = /Skip_EndRegion_Comment #include <misc.au3> If Not @Compiled Then Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("MouseCoordMode", 0) ;1=absolute, 0=relative Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced FileChangeDir(@ScriptDir) $dll = DllOpen("user32.dll") sleep(10000) Beep(500,500) While 1 If _IsPressed('35',$dll) Then tog_w() sleep(2000) EndIf WEnd Func tog_w() If _IsPressed('57') Then Send('{w up}') Else Send('{w down}') EndIf EndFunc ;==>tog_w Link to comment Share on other sites More sharing options...
Tvern Posted July 18, 2010 Share Posted July 18, 2010 You need to put a short sleep in the main while loop. Something as short as 10 ms will be more than enough. This goes for pretty much any loop. If you don't use the sleep the loop will just execute as fast as your computer can handle, so even if you made the contents of the loop half as cpu intensive, it would just double it's execution speed so it saturates the cpu. Link to comment Share on other sites More sharing options...
cal Posted July 19, 2010 Author Share Posted July 19, 2010 that works. Thanks. 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