Skip to main content
gamedev.net
🔒 Locked

Sending input data

Started by Exellion Jul 17, 2003 at 2:36 PM 4 replies 1k views
Original Post
Exellion
Exellion
Hi, Im looking for a way to send data to a DirectInput device (the keyboard mainly). Maybe send isn't the right word, so to be more precise I would like some kind of functions that "simulates" user input from the device. For example, I call my function with the arguments DIK_LEFT and a bool specifying up or down. Then I want the computer to believe that the left arrow key was just pressed/released. Is it possible to create such a function using DirectInput (or something just as low-level)? Thanks! [edited by - Exellion on July 17, 2003 3:37:34 PM]
Gilzu
Gilzu
Try to PostMessage() it. By doing that, you simulate any message
you want. including key storkes, mouse moves ect.

1. Check out which message you would like to send, in your case
you are looking for WM_KEYDOWN or WM_KEYUP.
2. Check out which parameters it requires (usually found in
MSDN). in your case, wParam=VK_LEFT and lParam=1.
3. Send data via PostMessage.

Heres some code with it:


PostMessage(NULL, (UINT)WM_KEYDOWN, (WPARAM)VK_LEFT, (LPARAM)1)




Gil Zussman
Check out Goose Chase, Coming this fall!
http://www.gilzu.com
[email=gil@gilzu.com]Gil Zussman[/email]Check out Goose Chase, Coming this fall!http://www.gilzu.com
Exellion
Exellion
Thanks for the reply, but maybe I should have explained a little more in detail. I want the function to work in all (or at least virtual all) cases. By sending window messages, only programs that actually uses the messages for keyboard input will respond to my function. Neither GetAsyncKeyState or DirectInput''s functions IDirectInputDevice8::GetDeviceData and IDirectInputDevice8::GetDeviceState will notice it. And I can safely assume that most games doesn''t use window messages to process user input. There certanly must be a low-level way of simulating keyboard input so that all applications, irrespective of way of handling it, will believe that the key was pressed.
I hope that made it a bit clearer.
jacklin
jacklin
Look into SendInput(). It does exactly what you want.
Sabonis
Sabonis

BOOL Keyboard::IsKeyDown( int Key )
{

// Check if the key was set

if( m_KeyBuffer[Key] & 0x80 )
return TRUE;
else
return FALSE;

}

try making a keyboard class, this one i used to check if a key was down. If you want the whole class, drop me a line at c_chack@yahoo.com
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein (1879-1955) That is so very true...
Exellion
Exellion
Thanks a bunch jacklin!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.