Skip to main content
gamedev.net
🔒 Locked

Direct Input Problems

Started by The Lion King Jun 1, 2004 at 2:25 AM 4 replies 800+ views
Original Post
The Lion King
The Lion King
Hi, I have been facing a few problems reagrding Direct Input lately, but I was able to solve them on my own accord (GOOD for me ) ... but I still want to know what I was doing wrong there, here are the problems: 1. When I try to Initialize KeyBoard (in Direct Input) it can either be for a FOREGROUND Window or a BACKGROUND Window ... the problem is that it doesn''t initialize through FOREGROUND, however, BACKGROUND works for me. Have anyone faced this sort of problem yet? But the app I am building is Windowed ... so if exiting the app is through ESC Key and it is pressed in another window, then the app will quit. I used the Active status of the Window to acquire and unacquire the Input Device to prevent the application from recieving Input if it is not Active. That solved my problem ... but why cant I initialize the Device by setting it to a FOREGROUND Window? Is there any extra stuff required? 2. When getting coordinates of the Mouse through Direct Input, it gives the movement of the Mouse Device ... not the movement or position of the cursor on the screen! Why is that? Is that useful? (I think in FPS Games) I used the Window Function GetCursorPos() to get the the current cursor position on the screen and that solved the problem. But isnt there anything for that in Direct Input? 3. I will be using Direct3D to set a cursor image for the Cursor of the app (Windowed) (in two or three days), will that effect the GetCursorPos() function for the Window or not? Thanks! Hope I explained my problems right :!
michaweyel
michaweyel
1. Hmmm, normally FOREGROUND access should always be possible for the keyboard. However, i think if your app doesn''t have the focus (window in background), you wont be able to acquire the device if you set the cooperative level to foreground access. Also, you have to reacquire the device every time your window goes from backgroud to foreground (does SetCooperativeLevel fail if you try foreground access?).

2. DirectX won''t report you absolute mouse coordinates. You could keep track of them yourself by setting the pos to some known screen position at startup and then adding up all relative movements or use GetCursorPos() like you did (may be a performance hit but i don''t know).

3. Don''t know for sure, but changing the cursor image with a DX-function should not affect GetCursorPos().
The Lion King
The Lion King
quote:
Original post by michaweyel
1. Hmmm, normally FOREGROUND access should always be possible for the keyboard. However, i think if your app doesn't have the focus (window in background), you wont be able to acquire the device if you set the cooperative level to foreground access. Also, you have to reacquire the device every time your window goes from backgroud to foreground (does SetCooperativeLevel fail if you try foreground access?).

2. DirectX won't report you absolute mouse coordinates. You could keep track of them yourself by setting the pos to some known screen position at startup and then adding up all relative movements or use GetCursorPos() like you did (may be a performance hit but i don't know).

3. Don't know for sure, but changing the cursor image with a DX-function should not affect GetCursorPos().

Thanks ... but for the first part (1) ... I am doing the samething for BACKGROUND ... I mean when the Window is not active, I have to UnAcquire the Device and when it goes back active, then I Acquire it again. Just wanna know why can't I initialize by setting it to FOREGROUND?

quote:
Original post by michaweyel
does SetCooperativeLevel fail if you try foreground access?

And YES! it fails when I set to FOREGROUND access!


[edited by - The Lion King on June 1, 2004 4:06:01 AM]
michaweyel
michaweyel
Sorry, no clue on that...however i got it working in an app of mine, i can check it out when i get home an post my code then.

Topic Locked

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

Sign in to reply to this topic.