Sign in to follow this  
Followers 0
Spooky

Hotkeys

5 posts in this topic

I'm experimenting with hotkeys. I wanted to try them out on a game. The goal is to open the ingame console - send a text command and have that command activated. Further, I need this thing to stay active and respond with the same action each time the ingame "p" key is pressed.

It would (I think) look something like this:

Send("{END}gamelogic.togglepause{ENTER}")

When the ingame "p" key is pressed the autoit script would activate - The {END} opens the ingame console - the text command "gamelogic.togglepause" is sent - the {ENTER} activates the command ingame.

I stated with this kludged up code:

HotKeySet("p", "TPause")

Func TPause()
While 1
    If ProcessExists("BF2.exe") Then
        Send("{END}gamelogic.togglepause{ENTER}")
    MsgBox(0, "Example", "BF2 is running.")
EndIf
WEnd
EndFunc

The "p" is a key in game, and the BF2.exe is the game executable. The above code obviously doesn't work. I looked around the forum and only saw things to pause or activate scripts and tried some of them out, couldn't get them to send anything to the game console. Any help?

Thank You

Share this post


Link to post
Share on other sites



I'm experimenting with hotkeys. I wanted to try them out on a game. The goal is to open the ingame console - send a text command and have that command activated. Further, I need this thing to stay active and respond with the same action each time the ingame "p" key is pressed.

It would (I think) look something like this:

Send("{END}gamelogic.togglepause{ENTER}")

When the ingame "p" key is pressed the autoit script would activate - The {END} opens the ingame console - the text command "gamelogic.togglepause" is sent - the {ENTER} activates the command ingame.

I stated with this kludged up code:

HotKeySet("p", "TPause")

Func TPause()
While 1
    If ProcessExists("BF2.exe") Then
        Send("{END}gamelogic.togglepause{ENTER}")
    MsgBox(0, "Example", "BF2 is running.")
EndIf
WEnd
EndFunc

The "p" is a key in game, and the BF2.exe is the game executable. The above code obviously doesn't work. I looked around the forum and only saw things to pause or activate scripts and tried some of them out, couldn't get them to send anything to the game console. Any help?

Thank You

alot of newer games block keys so that your script won't even see that they're pressed. i'd say to try another key, like {PAUSE} or {PRINTSCREEN} alot of times they don't block ALL of the keys.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thats what I thought too. I'm not even sure i got the code right tho and want to make sure before i call it quits for this subject. Can anyone suggest some proper code?

alot of newer games block keys so that your script won't even see that they're pressed. i'd say to try another key, like {PAUSE} or {PRINTSCREEN} alot of times they don't block ALL of the keys.

Share this post


Link to post
Share on other sites

Thats what I thought too. I'm not even sure i got the code right tho and want to make sure before i call it quits for this subject. Can anyone suggest some proper code?

what you have looks ok at a glance, but you may want to go with if winactive("wintitle") instead of your if processexists() just because the process can exist without being the active window, and with send, it just goes to the active window.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

If that's your complete code then the script will terminate immediately after it sets the hotkey which means that it won't be around to intercept and process that hotkey. This code will keep the script in memory:

HotkeySet('p', 'TPause')
While 1
    Sleep(0x7FFFFFFF) ; Do nothing for a really long time (hotkeys are still intercepted)
WEnd

Additionally, if you set a hotkey 'P' and then somewhere in your script you Send() the P key, the script is going to trigger the hotkey. You need to disable the hotkey when you Send() and then re-enable it afterwards:

HotkeySet('p')
Send('{END}gamelogic.togglepause{ENTER}')
HotkeySet('p', 'TPause')

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0