Matty Posted March 31, 2007 Share Posted March 31, 2007 I've recently started playing a game and I've found it much faster to perform a certain task if I make one button press perform a series of button presses. For example... HotKeySet("x", "Buttons") Func Buttons() Send("{ALTDOWN}{LSHIFT}{ALTUP}") EndFunc When trying this out in notepad as a test (by switching ALTDOWN/UP with SHIFTDOWN/UP, and switching LSHIFT with the letter "a") it would replace x with a captial A. It would work perfectly. I could even hold x down and it would spam 'A's. But when I went in to the game, I'd press x and it wouldn't always perform the function. I could hold it down and it would appear to randomly work. If anyone knows how to fix my problem i'd be grateful! I'm not sure if it's a computer problem, i.e. the game's raping my CPU so there's none left for my script, but I seriously doubt that could be it. Purely because so little CPU is required for the script. Regards, Matt. Link to comment Share on other sites More sharing options...
Paulie Posted March 31, 2007 Share Posted March 31, 2007 I've recently started playing a game and I've found it much faster to perform a certain task if I make one button press perform a series of button presses. For example... HotKeySet("x", "Buttons") Func Buttons() Send("{ALTDOWN}{LSHIFT}{ALTUP}") EndFunc When trying this out in notepad as a test (by switching ALTDOWN/UP with SHIFTDOWN/UP, and switching LSHIFT with the letter "a") it would replace x with a captial A. It would work perfectly. I could even hold x down and it would spam 'A's. But when I went in to the game, I'd press x and it wouldn't always perform the function. I could hold it down and it would appear to randomly work. If anyone knows how to fix my problem i'd be grateful! I'm not sure if it's a computer problem, i.e. the game's raping my CPU so there's none left for my script, but I seriously doubt that could be it. Purely because so little CPU is required for the script. Regards, Matt.Thats odd, because the code you posted shouldn't work at all.... You have nothing that keeps the script from closing while it waits for you to push the hotkey. Link to comment Share on other sites More sharing options...
Matty Posted March 31, 2007 Author Share Posted March 31, 2007 Sorry that was just a sample, i've got the necessary means of keeping the hotkeys active. Link to comment Share on other sites More sharing options...
Paulie Posted March 31, 2007 Share Posted March 31, 2007 Sorry that was just a sample, i've got the necessary means of keeping the hotkeys active.Oh well, I'm afraid i don't encounter that same problem when I add a while loop in like I have below, HotKeySet("x", "Buttons") While 1 Sleep(100) WEnd Func Buttons() Send("{ALTDOWN}{LSHIFT}{ALTUP}") EndFunc I always seem to pick up the hotkeys with this... Maybe the problem has to do with something other than the hotkeys themselves. Might we see the whole script? Link to comment Share on other sites More sharing options...
Matty Posted March 31, 2007 Author Share Posted March 31, 2007 Oh well, I'm afraid i don't encounter that same problem when I add a while loop in like I have below, expandcollapse popupHotKeySet("x", "Buttons") While 1 Sleep(100) WEnd Func Buttons() Send("{ALTDOWN}{LSHIFT}{ALTUP}") EndFuncoÝ÷ Ø¥Á¬¬±ç¦¶brK©¶¡¢ÙÊÌ"¶aÃÉ·êk¡¹^¬¶hÂ+a²¶§az»aj{az-쬶¦±éozÃ"pzǶ°^±Êâ¦ßêº^jëh×6 HotKeySet("{HOME}", "Close") HotKeySet("x", "Buttons") HotKeySet("z", "Buttons2") $title = "Program" $WinCheck = 0 MsgBox(0,$title,"Text") WinWaitActive("Game") Func Buttons() Send("{ALTDOWN}{LSHIFT}{ALTUP}") EndFunc Func Buttons2() Send("{ALTDOWN}{LCTRL}{ALTUP}") EndFunc Func Close() MsgBox(0,$title, "Text") Exit EndFunc While $WinCheck = 0 WinWaitClose("Game") If @error = 1 Then $WinCheck = 0 Else $WinCheck = 1 EndIf WEnd MsgBox(0,$title, "Text") Thats all there is. I can explain a little about the purpose...It's for a racing game and it shifts gears by just pressing one button. Without this macro one would have to hold down the clutch, shift up or down gears and then release the clutch. When the hotkey stroke is actually picked up it works perfectly. Link to comment Share on other sites More sharing options...
Matty Posted March 31, 2007 Author Share Posted March 31, 2007 Tried a script like your's with just a sleep and no window detection and it still had the same problem! I've got no idea what is wrong! Link to comment Share on other sites More sharing options...
Paulie Posted March 31, 2007 Share Posted March 31, 2007 (edited) Well, I tried to re-write this code to see what it would do, here is what I came Up with. HotKeySet("{HOME}","Quit") HotKeySet("x","ShiftUp") HotKeySet("z","ShiftDown") If not WinExists("Game") then Do ToolTip("Waiting For Game...",0,0) Sleep(100) Until WinExists("Game") EndIf Do Sleep(100) ToolTip("Running...",0,0) If Not WinActive("Game") then Do ToolTip("Game is not active. Paused.",0,0) Sleep(100) Until WinActive("Game") EndIf Until Not WinExists("Game") Func ShiftUp() Send("{ALTDOWN}{LSHIFT}{ALTUP}") ToolTip("Shifting Up",0,0) EndFunc Func ShiftDown() Send("{ALTDOWN}{LCTRL}{ALTUP}") ToolTip("Shifting Down",0,0) EndFunc Func Quit() ToolTip("Exiting...",0,0) Sleep(3000) Exit EndFunc I used tooltips instead of Msgboxes because they are usually more game-friendly, however you can switch that however you want. If you still have this problem, try reducing the sleep. I'm not sure how frequently you are switching (more than once in every tenth of a second?) But This works for me with notepad. Edited March 31, 2007 by Paulie Link to comment Share on other sites More sharing options...
Matty Posted March 31, 2007 Author Share Posted March 31, 2007 Thanks for the script but I'm still getting the same problems! I'm guessing its not a problem with AutoIt but with my computer and the demand of the game. All the scripts I've tested work perfectly in notepad but I get problems in game. I tried one with sleep 10000 and the problem's still there. Thanks again. I'm going to try a different language and see if that works. Link to comment Share on other sites More sharing options...
The Kandie Man Posted March 31, 2007 Share Posted March 31, 2007 (edited) Try this at the beginning of the script:ProcessSetPriority (@AutoItPID, 4) This will set the autoit script's process priority to high, it should therefore respond better when you are running something that is cpu intensive along with it. This will, however, "steal" some processing power from other processes that are currently running at a lower priority level, such as your game. Edited March 31, 2007 by The Kandie Man "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire Link to comment Share on other sites More sharing options...
Matty Posted March 31, 2007 Author Share Posted March 31, 2007 Hehe it's funny you just wrote that! I tried changing priority in taskmanager to high and it seemed to make little difference, however it did work more often. It appears that we've found the problem. I even tried giving AutoIt one core and my game the other core...Just made the game a bit laggy Looks like I'm going to have the hook into the game to get it to work flawlessly. Cheers for all your help guys. Link to comment Share on other sites More sharing options...
MrPink Posted May 3, 2007 Share Posted May 3, 2007 (edited) try this one at the beginning of your script: Opt("SendKeyDownDelay", 100) ;100 milliseconds by default keystrokes from autoit are only 5ms .. for some games you need a longer period for the game to detect the keystroke Edited May 3, 2007 by MrPink 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