Jump to content
  • Advertisement
Sign in to follow this  
Belkacem

directinput and keybd_event problem !

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
thank you for your reply ..

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 ).

Share this post


Link to post
Share on other sites
Are you sure about your PeekMessage logic? It looks to me that you only poll the joystick when there are events, and when there aren't events you translate and dispatch them. Would it not be better to Peek the events in a loop, and when you run out of events then unconditionally poll the joystick?

Full disclosure: I'm not a Win32 programmer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!