You can force a "key press" using a WinAPI, no problem there.
But as long as that pesky F1 control menu is enabled in your game, there is no way to check which keys the player has set for which "buttons" there, not without opening the engine's DLL to check where that data is stored (you can actually read that from the registry too, but I won't go there, sorry).
If you use a custom keyboard script, AND disable the built-in F1 setting menu, than you can force a key press without worrying about these controls.
You can use this snippet for that:
Spoiler
Code:
class << Input
SendInput = Win32API.new('user32', 'SendInput', 'ipi', 'i')
def press_keys(*kys) # args: (key_code1,key_code2,...)
ary = []
kys.each {|ky| ary.push(1,ky,0) }
inputs = ary.pack('LSx2Lx16'*kys.size)
SendInput.call(kys.size, inputs, 28)
end
def release_keys(*kys) # args: (key_code1,key_code2,...)
ary = []
kys.each {|ky| ary.push(1,ky,2) }
inputs = ary.pack('LSx2Lx16'*kys.size)
SendInput.call(kys.size, inputs, 28)
end
def queue_keys(*kys) # args: ([key_code1,0/2],[key_code2,0/2],...)
ary = [] # 0 = press, 2 = release
kys.each {|ky| ary.push(1,*ky) }
inputs = ary.pack('LSx2Lx16'*kys.size)
SendInput.call(kys.size, inputs, 28)
end
end
You can use it with these code lines from anywhere:
Code:
Input.press_keys(key_code1,key_code2,...)
Input.release_keys(key_code1,key_code2,...)
Input.queue_keys([key_code1,0/2],[key_code2,0/2],...)
Replace the
key_codeX arguments with any valid keycodes. You must know the code of the key you want to press for this, obviously.
For example,
ALT is 18,
ENTER is 13,
X is 88, and so on.
You can search on google for keycodes easily, there are many sites with nice key code tables.
Make sure to search for decimal key codes, not hexadecimals. I never tested with hexadecimals, so no idea if the code works with those or not.
You can add multiple keys to be pressed at the same time if you want as well.
Note that once you "press" a key like this, it will remain pressed until you "release" it with the other code line, or until the player presses the key on the keyboard manually twice.
You WILL need proper scripting experience to do anything with this, you can't just randomly force key presses, or else you might even break your game.
I don't know for what do you want to use this, but now you have a way to do it, or at least the basics of it.
Never did I see anything like that blocked by any anti-malware program. It is a simple API usage. APIs are made to be used.
If something blocks this, than you should get rid of that something, because it is clearly a bad thing to have on any PC.