Sign in to follow this  
Belkacem

directinput and keybd_event problem !

Recommended Posts

Belkacem    100
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 .


[code]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);
}[/code]
}


this code not work

[quote] 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
Evil Steve    2017
DirectInput works at a lower level than keybd_event, so you can't use keybd_event to send messages to DirectInput.

However, [url="http://www.gamedev.net/blog/233/entry-1567278-reasons-not-to-use-directinput-for-keyboard-input/"]you should never, ever be using DirectInput for keyboard input[/url] in any case, so it's not really a problem.

Share this post


Link to post
Share on other sites
Belkacem    100
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
rip-off    10976
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this