DirectInput :: Which key was pressed?
Hi, I''m trying to implement a menu where the user can change controls. To do this I need a way to know if a key has been pressed and if so, which key (or mouse/joystick button)? Do you know of a slick way of achieving that with DirectInput? Do I have to use buffered input?
Thanks.
DirectInput was really made for fast controls. It can handle menu selection, but that is not what it was meant for. It will be much easier if you just use standard Win32 messages for your menus.
DirectInput immediate mode is so fast that you really can''t use it for menus at all. If you want to use DirectInput, you''ll need to use buffered mode. But in general, Win32 messages are the easiest as well as the cleanest solution to this.
neneboricua
DirectInput immediate mode is so fast that you really can''t use it for menus at all. If you want to use DirectInput, you''ll need to use buffered mode. But in general, Win32 messages are the easiest as well as the cleanest solution to this.
neneboricua
I have no problem with the speed, my menu is working fine, I just want to know how to retrieve which key/button was pressed. Does Win32 messages handle joystick input?
quote:
Does Win32 messages handle joystick input?
I''m 99.9% sure it does not. You need to interface with the joystick drivers to get joystick data, something that DirectInput does for you ( I think that''s how it works ).
Stay Clausal,
Red Sodium
When DirectX_Event is triggered by a button press, you have to scan the array of buttons and determine which one was pressed. If multiple buttons are pressed at once, I guess you would automatically stop at the first one. How you handle that is up to you.
As far as I know, DirectInput cannot and will not tell you specifically which button was pressed. It will tell you if a button was pressed, but you have to figure out which one it was.
As far as I know, DirectInput cannot and will not tell you specifically which button was pressed. It will tell you if a button was pressed, but you have to figure out which one it was.
DirectInput is probably what you want to use. It isn''t too difficult to use. Take a look at the DirectInput samples. Here is some code that handles mouse input to get you started.
static void InitializeMouse( HINSTANCE hInstance, HWND hWnd ){ OutputDebugString( "***InitializeMouse\n" ); HRESULT hr; hr = DirectInput8Create( hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&s_pDI, NULL ); assert_succeeded( hr ); hr = s_pDI->CreateDevice( GUID_SysMouse, &s_pMouseDevice, NULL ); assert_succeeded( hr ); hr = s_pMouseDevice->SetDataFormat( &c_dfDIMouse2 ); assert_succeeded( hr ); hr = s_pMouseDevice->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND ); assert_succeeded( hr ); s_pMouseDevice->Acquire();}static void ShutDownMouse(){ OutputDebugString( "***ShutDownMouse\n" ); if( s_pMouseDevice ) { s_pMouseDevice->Unacquire(); } SAFE_RELEASE( s_pMouseDevice ); SAFE_RELEASE( s_pDI );}static void UpdateMouse( __int64 time ){ HRESULT hr; DIMOUSESTATE2 dims2; // DirectInput mouse state structure if ( s_pMouseDevice == NULL ) { return; } memset( &dims2, 0, sizeof(dims2) ); hr = s_pMouseDevice->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); if ( FAILED( hr ) ) { hr = s_pMouseDevice->Acquire(); while ( hr == DIERR_INPUTLOST ) { hr = s_pMouseDevice->Acquire(); } return; } s_pCamera->Yaw( s_MouseSensitivity * dims2.lX ); s_pCamera->Pitch( s_MouseSensitivity * dims2.lY ); s_pCamera->Roll( s_MouseSensitivity * dims2.lZ );}
You should use DirectInput action mapping. What you want to achieve is what action mapping was designed for.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement