• 13
• 18
• 19
• 27
• 10

# directinput and keybd_event problem !

This topic is 2443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello again !

i create simple application that simulate keyboard event and joystick event , for keyboard event i use simple API called keybd_event() and for joystick i use direct input .

now if i call keybd_event() without direct input it work correctly and i succeeded to send the keyboard event .

but my problem is that my application ignore keybd_event()function if i called with direct Input

this code is work without direct input and it work .

if ( ::PeekMessageA ( &Msg , NULL , 0U , 0U , PM_REMOVE| PM_NOYIELD)) { ::TranslateMessage ( &Msg); ::DispatchMessageA ( &Msg); } else { if ( ::GetAsyncKeyState ( 'T' )) { ::SetFocus ( wnd ); keybd_event(VK_UP,0x048,KEYEVENTF_EXTENDEDKEY | 0,0); Sleep(100); keybd_event(VK_UP,0x048, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0); }
}

this code not work

HRESULT poll(DIJOYSTATE2 *js)
{

joystick->Poll();

joystick->Acquire();

if ( ::GetAsyncKeyState ( 'T' ))
{
::SetFocus ( wnd );
keybd_event(VK_UP,0x048,KEYEVENTF_EXTENDEDKEY | 0,0);
Sleep(100);
keybd_event(VK_UP,0x048, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);
}

// Get the input's device state
joystick->GetDeviceState(sizeof(DIJOYSTATE2), js);

return S_OK;
}

if ( ::PeekMessageA ( &Msg , NULL , 0U , 0U , PM_REMOVE| PM_NOYIELD))
{
::TranslateMessage ( &Msg);
::DispatchMessageA ( &Msg);

}

else
{
poll(&js);
}[/quote]

any help !! and thank you !!

##### Share on other sites
DirectInput works at a lower level than keybd_event, so you can't use keybd_event to send messages to DirectInput.

However, you should never, ever be using DirectInput for keyboard input in any case, so it's not really a problem.

##### Share on other sites

i think i don't explain my idea correct .

i have a race game does not support joystick ( wheel ) , it support keyboard only .

OK . now my idea is like this :

1- create application using direct Input to detect my wheel .
2- if i get a message from joystick i send a message to the game passing the value that i want

example :

if i get acceleration button ( button 2 ) i send a message to the game passing value ( VK_UP ).