sebastian Posted January 2, 2006 Posted January 2, 2006 (edited) Hello everybody I just wrote my first script, but it doesn't work the way I intended it to. Everything's just fine as long as I stay on the desktop or some application. But as soon as Battlefield2 is the active window, AutoIt doesn't capture the hotkey anymore and doesn't execute the function: HotKeySet('{PAUSE}', 'DoRoll') ;Body of programm While 1 Sleep(10) WEnd ; Func DoRoll() Opt('SendKeyDownDelay', 500) Opt('SendKeyDelay', 500) ;Send('{CTRLDOWN}') Send('{a down}') MsgBox(0, 'AutoIt', @AutoItVersion) EndFunc How can I make this work with the game as active windows? Any ideas? Edited January 2, 2006 by sebastian
seandisanti Posted January 3, 2006 Posted January 3, 2006 Hello everybody I just wrote my first script, but it doesn't work the way I intended it to. Everything's just fine as long as I stay on the desktop or some application. But as soon as Battlefield2 is the active window, AutoIt doesn't capture the hotkey anymore and doesn't execute the function: HotKeySet('{PAUSE}', 'DoRoll') ;Body of programm While 1 Sleep(10) WEnd ; Func DoRoll() Opt('SendKeyDownDelay', 500) Opt('SendKeyDelay', 500) ;Send('{CTRLDOWN}') Send('{a down}') MsgBox(0, 'AutoIt', @AutoItVersion) EndFunc How can I make this work with the game as active windows? Any ideas?first i want to commend you on the first line that i bolded. every day we see 'this isn't working right' posts, when the function being blamed is typically just being used incorrectly.it looks like your code is sound, so i'd guess the game is just trapping your keypresses before they reach the script. That's normal for newer games. typically i suggest that people try to use 'pause' or printscreen, or other keys that may have been overlooked, but since you're already using {PAUSE} those keys may not work in your case. One thing that you could try, is use a code that watches for ANY keypress, and perform an action if a key is pressed... then just press everything and see if anything causes a reaction from the script... one second i'll find an old post that i'm reminded of and tailor the script accomplish what i suggest...
seandisanti Posted January 3, 2006 Posted January 3, 2006 first i want to commend you on the first line that i bolded. every day we see 'this isn't working right' posts, when the function being blamed is typically just being used incorrectly.it looks like your code is sound, so i'd guess the game is just trapping your keypresses before they reach the script. That's normal for newer games. typically i suggest that people try to use 'pause' or printscreen, or other keys that may have been overlooked, but since you're already using {PAUSE} those keys may not work in your case. One thing that you could try, is use a code that watches for ANY keypress, and perform an action if a key is pressed... then just press everything and see if anything causes a reaction from the script... one second i'll find an old post that i'm reminded of and tailor the script accomplish what i suggest...this is from a script that gafrost wrote to do something else (i don't remember exactly what, sorry gary) then i used in a script to watch for inactivity. I've removed the inactivity stuff, so that now if a key is pressed, it should just give you a message that it saw the key. and it'll give you the hex value of the key. I don't know which if any of the non character keys are included, i'm going to test that myself and may have to post a revision if keys are excluded, but all you have to do is run script, then launch game and start pressing keys. #include <Misc.au3> HotKeySet("{Esc}", "_Exit") Dim $s_keys[117] = [116, _ "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", _ "11", "12", "13", "14", "1B", "20", "21", "22", "23", "24", _ "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", _ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", _ "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", _ "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", _ "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", _ "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", _ "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", _ "7B", "7C", "7D", "7E", "7F", "80H", "81H", "82H", "83H", "84H", _ "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"] $dll = DllOpen("user32.dll") While 1 Sleep(100) For $y = 1 To $s_keys[0] If _IsPressed ($s_keys[$y], $dll) Then MsgBox(0, "I saw that one!", $s_keys[$y]) EndIf Next WEnd Func _Exit() DllClose($dll) Exit EndFunc
Moderators SmOke_N Posted January 3, 2006 Moderators Posted January 3, 2006 errr... errr.... 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.
seandisanti Posted January 3, 2006 Posted January 3, 2006 this is from a script that gafrost wrote to do something else (i don't remember exactly what, sorry gary) then i used in a script to watch for inactivity. I've removed the inactivity stuff, so that now if a key is pressed, it should just give you a message that it saw the key. and it'll give you the hex value of the key. I don't know which if any of the non character keys are included, i'm going to test that myself and may have to post a revision if keys are excluded, but all you have to do is run script, then launch game and start pressing keys. #include <Misc.au3> HotKeySet("{Esc}", "_Exit") Dim $s_keys[117] = [116, _ "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", _ "11", "12", "13", "14", "1B", "20", "21", "22", "23", "24", _ "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", _ "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", _ "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", _ "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", _ "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", _ "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", _ "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", _ "7B", "7C", "7D", "7E", "7F", "80H", "81H", "82H", "83H", "84H", _ "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"] $dll = DllOpen("user32.dll") While 1 Sleep(100) For $y = 1 To $s_keys[0] If _IsPressed ($s_keys[$y], $dll) Then MsgBox(0, "I saw that one!", $s_keys[$y]) EndIf Next WEnd Func _Exit() DllClose($dll) Exit EndFuncthis looks to work for every key on my keyboard, but i can't say i'm surprised; gafrost does awesome work. you may want to hold the keys in for a second or so each, just to make sure that the ispressed has time to check all of the keys to see which is pressed.
Moderators SmOke_N Posted January 3, 2006 Moderators Posted January 3, 2006 _IsPressed does a DllCall to user32.dll ... do you need ot have the $DLL in the parameter... I mean do you have to have DllOpen()/DllClose() since this is the case? 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.
seandisanti Posted January 3, 2006 Posted January 3, 2006 _IsPressed does a DllCall to user32.dll ... do you need ot have the $DLL in the parameter... I mean do you have to have DllOpen()/DllClose() since this is the case?i honestly don't know, i just used the code as-is because i trust gary's abilities. i'm not one of those people that's constantly trying to point out other people's inefficiencies to make them feel bad <cough> ron <cough>. kidding...
Moderators SmOke_N Posted January 3, 2006 Moderators Posted January 3, 2006 i honestly don't know, i just used the code as-is because i trust gary's abilities. i'm not one of those people that's constantly trying to point out other people's inefficiencies to make them feel bad <cough> ron <cough>. kidding...Ha!!, I wasn't pointing out inefficiencies (not comparing in the shower here), it was a serious question... lmao. 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.
seandisanti Posted January 3, 2006 Posted January 3, 2006 Ha!!, I wasn't pointing out inefficiencies (not comparing in the shower here), it was a serious question... lmao.that's what makes what i said a joke. but seriously though, i really don't know. perhaps if he's feeling generous today gafrost could dumb it down for us...
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