The search function is quite handy, however, I still cannot seem to figure this out. I'm trying to write a little program that sends little daily messages from the server in the game Halo. I have this server and in order to send a message, you have to press 'T' to bring up the chat-box, then type your message, then press enter to send it.
I used the keybd_event function like so..
just to send the letter 'A' through.
keybd_event('T',0,0 , 0);
keybd_event('T',0,KEYEVENTF_KEYUP , 0);
keybd_event('A',0,0 , 0);
keybd_event('A',0,KEYEVENTF_KEYUP , 0);
keybd_event(VK_RETURN,0,0 , 0);
keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP , 0);
However, it won't bring up the chatbox and nothing happends in the end. If I press T manually in the game to bring it up, the rest executes fine. So, the problem is, using keybd_event function to press 'T' to bring up the chatbox doesn't work. Does it have to do with direct3d 9? Not that I want to go into this option, but could I force the asm function that brings up the chatbox? Would using SendInput() or SendMessage() do anything different for me?
Well, you are really suppose to use SendInput (or somthing similar, I forget). keybd_event is depreciated.
Have you checked to see if it even works in a simple program like Notepad or somthing?
And before simulating key presses, you should call SetFocus.
None of those methods work with DirectInput/DirectX.
I have gotten it to work. In the first post, I said the only part that doesn't work is bringing up the chatbox with 'T'. It can manually type letters and hit enter just fine. I will try out SendInput and see what happens. Thanks for help.
Originally Posted by Yarin
GG? Are you actually trying to insult my intelligence? Well, smarty-pants, what method does work with DirectInput and/or DirectX?
Originally Posted by Codeplug
First ensure that the target window is in the foreground ie has focus.
Have you registered the 'T' as an Accelerator (key stroke combination used to 'accelerate' use of menus etc). Look at LoadAccelerators() or CreateAcceleratorTable().
Looks like the TranslateAccelerator() function is not catching the 'T' or you are calling TranslateMessage() after it has been recognised as an accelerator. If TranslateAccelerator() returns non zero you should not call TranslateMessage() [as it turns the accelerator into a normal key stroke].