|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| DirectX 8 and the Keyboard |
|
![]() alberto_balsalm Member since: 11/7/2001 |
||||
|
|
||||
| there was nothing bad about the tutorial, but i thought it was just a rewritten version of the tutorial (which is better) that microsoft has put in the SDK. To improve this tutorial you have to add something that isn't in the original tutorial.. |
||||
|
||||
![]() masonium Member since: 7/26/2001 From: IN, USA |
||||
|
|
||||
| Really? I didn't even look at the DirectX SDK tutorial when I was writing it. My next tutorial is on DirectAudio. It's actually much more detailed than this one, providing information on the different paramters as well as info on using some common functions, such as stopping sounds and setting loops. No, HTML is not an OO language. |
||||
|
||||
![]() Hanzo Member since: 10/12/2001 From: Arvada, USA |
||||
|
|
||||
| I've got a question, masonium. I have used a very similar set of code for my current projects (actually, it's near identical) yet I have noticed a very odd side effect I'm having trouble preventing: I'm currently working in a directdraw window (ie: NOT fullscreen) and I have noticed that when running my program, if I change the focus to another window (say, WinAmp), my program begins to process input requests! It's as though input is being sent to my program from other windows. Ever heard of this? How do you prevent it...I guess the correct question is: How do you prevent interference from other windows to the directinput calls your program makes while in the background? I could just pause the game execution when the window loses focus via WM_ACTIVATEAPP, but this is going to be a net-playable game and will potentially sit in the background on occaision, so this isn't really an option for me. - Hanzo Edited by - Hanzo on January 2, 2002 12:29:22 AM |
||||
|
||||
![]() Oluseyi Staff Member since: 5/14/2001 From: New York, NY, United States |
||||
|
|
||||
| Hanzo: Unacquire the device when it's in the background. I thought Samurai Showdown was an excellent series... [ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ] Thanks to Kylotan for the idea! |
||||
|
||||
![]() Hanzo Member since: 10/12/2001 From: Arvada, USA |
||||
|
|
||||
| Just a simple call to (mykeyboarddevice)->Unaquire() should do this? (ie: no need to ->Release(), I would expect). Good tip, while you posted that I actually went ahead with a solution partially based on my "paused" methodology: I simply stop reading from my directinput object if the window goes to the background. I wonder which is the *preferred* way... - Hanzo PS: I played so much SS2 I wrote a FAQ on it: http://db.gamefaqs.com/coinop/arcade/file/samurai_shodown_2.txt :D UPDATE: Oluseyi, I tried the unaquire() method for fun, no go: 1. My readinput() function is written to automatically reaquire whenever input is lost. 2. If that reaquire() code snippet is moved out of readinput() and put in main game loop (with its own sanity logical check for being in the background), the actual readinput() call is still made, whether a reaquire() was done or not. 3. When the readinput() gets called, regardless of the input device having been unaquired, input is **still** being passed by another window. Just an FYI. Strangely, the first solution still seems to be the best bet so far (and not unaquiring doesn't seem to have an after-effect, ie: I can still load up notepad and write a letter, without causing any keypresses to pass back into the game). Edited by - Hanzo on January 3, 2002 1:31:51 AM |
||||
|
||||
![]() LOWORBIT Member since: 5/13/2001 From: USA |
||||
|
|
||||
| Try this to prevent accessing the keyboard while not having focus. In all my windows programs I insert a line if( g_hWnd == GetActiveWindow()) after checking to see if there's any windows messages i need to process, this is in my main loop. What this does is allows me to limit what i process, because the line after that is UpdateHandler(); and if it returned false I call WaitMessage which is a windows function that waits until a message is sent, while that may seem to be a bad idea, but windows sends various messages saying that you've gotten focus back Anyways, sense your app is running in windowed mode (this is more ideal for a fullscreen app) this can be easily changed by adding a boolean saying if the application is fullscreen or not so you can call the drawing routine, or pause game and not update the screen at all. Your supposed to release the keyboard/mouse/joystick when you don't have focus, so you may want a function that unaquires the keyboard when you lose focus. gDI is a class wrapper I made for DirectInput 7 then converted to 8 that supports keyboard/ complex mice and joysticks in imediate mode, the Close function actually completley releases directinput which isn't needed. Hope this helps. while( TRUE ) { // msg if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { if( 0 == GetMessage(&msg, NULL, 0, 0 ) ) { // WM_QUIT was posted, so exit, quit return (int)msg.wParam; } // Translate and dispatch the message if( 0 == TranslateAccelerator( g_hWnd, hAccel, &msg ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } else { if( g_hWnd == GetActiveWindow()) //if the window is the focus { //MAIN LOOP BELOW UpdateHandler(); //MAIN LOOP ABOVE } else { // Make sure we go to sleep if we have nothing else to do gDI->Close(); WaitMessage(); } } } Edited by - loworbit on January 3, 2002 1:22:08 AM |
||||
|
||||
![]() intrest86 Member since: 12/16/2001 From: Baltimore, MD, United States |
||||
|
|
||||
| OK, tell me if I am wrong, but don't you just Set the Cooperative Level to ForeGround instead of BackGround? |
||||
|
||||
![]() B-Barlow Member since: 6/22/2001 |
||||
|
|
||||
| Using the code from this tutorial I seem to be getting about a 1 second delay between pressing or releasing a key and seeing my program respond. Any idea what would cause that? Edited by - B-Barlow on January 4, 2002 11:16:24 PM |
||||
|
||||
![]() masonium Member since: 7/26/2001 From: IN, USA |
||||
|
|
||||
| B-Barlow: I haven't had that happen in my program, so I'm not sure what would cause it. Try using DISCL_FOREGROUND instead of background and try using exclusive access. When you set the cooperative level via the SetCooperativeLevel function, you can use DISCL_FORGROUND instead of DISCL_BACKGROUND so that the program won't recieve input when it's out of focus, like intrest86 suggested. For those who are confused with DISCL_EXCLUSIVE vs, DISCL_NONEXCLUSIVE, here's some info from the docs that might be useful: Exclusive vs. Nonexclusive In most cases, the fact that your application is using a device at the exclusive level does not mean that other applications cannot get data from the device. However, it does mean that no other application can also acquire the device exclusively ... To use force-feedback effects, an application must have exclusive access to the device. ... when an application has exclusive access to the system mouse, created by passing GUID_SysMouse to IDirectInput8::CreateDevice, Windows is not allowed any access and no mouse messages are generated. A further side effect is that the cursor disappears. ... When an application has exclusive access to the keyboard, DirectInput suppresses all keyboard messages except CTRL+ALT+DEL and, on Windows 95 and Windows 98, ALT+TAB. Under Windows 2000, no application launched subsequently to the exclusive-mode DirectInput application can get keyboard data. No, HTML is not an OO language. Edited by - masonium on January 4, 2002 12:01:07 AM |
||||
|
||||
![]() B-Barlow Member since: 6/22/2001 |
||||
|
|
||||
| hmm... Neither DISCL_FOREGROUND or DISCL_EXCLUSIVE had any affect. I'm befuddled Are there any other ways I can access the keyboard that might work or is this as low as I can go under windows? |
||||
|
||||
![]() masonium Member since: 7/26/2001 From: IN, USA |
||||
|
|
||||
| No I checked the docs for DirectInput and they don't seem to offer any alternative besides that. Are you doing anything else in the application that might effect the input? Are you unacquiring the devices manually when the app loses focus or anything like that? |
||||
|
||||
![]() B-Barlow Member since: 6/22/2001 |
||||
|
|
||||
| Nope. it's pretty bare bones at this state. Not much going on at all. Just had a weird idea though. I'm going to change my keyboard typematic rate dealy and see if that has anything to do with it. I know it shouldn't, but I've seen stranger things happen. -edit- nope. no change. perhaps something screwy in my BIOS settings? Don't worry about it though. I'll play around and see if I can figure out what's up. Edited by - B-Barlow on January 4, 2002 12:29:19 AM |
||||
|
||||
![]() B-Barlow Member since: 6/22/2001 |
||||
|
|
||||
| Well it appears to work fine in full screen mode. I was running windowed before for debugging purposes. How ironic. Edited by - B-Barlow on January 4, 2002 12:57:49 AM |
||||
|
||||
![]() masonium Member since: 7/26/2001 From: IN, USA |
||||
|
|
||||
| I'm probably going to write another tutorial on DirectInput, probably with joysticks and a more OO class wrapper for the input. I'm having a hard time, though, deciding whether to cover action mapping or force feedback. Which would you be more interested in? I appreciate your input No, HTML is not an OO language. |
||||
|
||||
![]() B-Barlow Member since: 6/22/2001 |
||||
|
|
||||
| Action mapping. Of course I don't own any force feedback stuff |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| I have noticed a problem with all of the docs and tutorials regarding the keyboard. According to the MS docs as well as some of the tutorials I've seen, GetDeviceState() requires a char** - that is to say, the address, of an array of 256 bytes. As in: char aKeys[256]; GetDeviceState( ..., 256, &aKeys ); This causes an exception in my current project. This particular tutorial actually states that it should be the address of the array as in: GetDeviceState( ..., 256, aKeys ); which would be consistant with all of the other devices (which take addresses to structures). Doing it this way does not crash my project - but unfortunately, I get garbage data. So which is it? Anybody know? Cheers, Darryl |
||||
|
||||
![]() EkEk Member since: 8/28/2003 From: Jakarta, Indonesia |
||||
|
|
||||
| hey everyone, i'm sorry if my question seems silly! but i'm really new beginner in programming. masonium i've read your tutorial about direct input. but when i compile your code, it went error like this: error C2065: 'DirectInput8Create' : undeclared identifier but when i change to DirectInputCreate the error is gone. i have installed directx 8.1 SDK and when I open the header file/dinput.h I found DirectInput8Create in there. This is really confusing, why the compiler doesn't recognize it?? [edited by - EkEk on October 23, 2003 1:15:52 AM] |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|