Hey guys,
I've written up a cheapie little SendKeys script that I'm intending to use with a DirectX-based game.
Here's the deal: It appears that everything is working properly with the script... What I'm trying to do is get it to register certain "game commands" every X (plus random interval between 0 and 10 seconds) seconds. But it doesn't work!
If I initiate the chat box for the game, then the keys are sent just fine. However, if I escape out of "chat mode", then, even though apparently the keys are being sent to the application (because if you go into chat mode they are being entered into the box), it is not registering the command associated with that key.
Do I need to do something else?
I've thought about doing a FindWindow to get the hWnd id for the app, then using a .SendMessage to the hWnd to send the command of the exact key that I'm trying to press (say, the number 4 - and not the one on the numpad, for instance just as an off-the-wall example). This would be a lot of extra work and, as I don't have too much experience with VBScript (as opposed to VBA) I couldn't quite get to nailing down how to call API from VBScript (which is just a simple Declare in VBA ...)
Any ideas?
I've written up a cheapie little SendKeys script that I'm intending to use with a DirectX-based game.
'################################
'# #
'# File: sendKeys.vbs #
'# #
'################################
Dim Wsh
Set Wsh = WScript.CreateObject("WScript.Shell")
Dim SEND_KEY
Dim MIN_REPEAT_INTERVAL
SEND_KEY = InputBox("Enter keys to send:")
MIN_REPEAT_INTERVAL = InputBox("Enter amount of seconds to repeat:")
While True
WScript.Sleep CLng((Rnd()*10000)+(CLng(MIN_REPEAT_INTERVAL)*1000))
Wsh.AppActivate "Random Program Name..."
Wsh.SendKeys SEND_KEY, True
Wend
Here's the deal: It appears that everything is working properly with the script... What I'm trying to do is get it to register certain "game commands" every X (plus random interval between 0 and 10 seconds) seconds. But it doesn't work!
If I initiate the chat box for the game, then the keys are sent just fine. However, if I escape out of "chat mode", then, even though apparently the keys are being sent to the application (because if you go into chat mode they are being entered into the box), it is not registering the command associated with that key.
Do I need to do something else?
I've thought about doing a FindWindow to get the hWnd id for the app, then using a .SendMessage to the hWnd to send the command of the exact key that I'm trying to press (say, the number 4 - and not the one on the numpad, for instance just as an off-the-wall example). This would be a lot of extra work and, as I don't have too much experience with VBScript (as opposed to VBA) I couldn't quite get to nailing down how to call API from VBScript (which is just a simple Declare in VBA ...)
Any ideas?