• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Mick is Stumped

keyboard GetDeviceData (buffered) never releases keys?

4 posts in this topic

Bottom line using the buffered methods GetDeviceData buffers presses but not releases!? Same with the laptop keyboard and a USB keyboard.

What could be going on here? Edit controls etc work just fine.

Disclaimer: the keyboard is part of a generic controller framework, and it is used for gamey inputs so I am not sure why Direct Input is unsuitable for that (as is often proclaimed; read: so please spare everyone the lecture) though raw input will probably be looked into as an alternative if it can distinguish between multiple keyboards. Not sure what to do if this won't work [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]

I remember having issues with buffered keyboard for "ghosting" in the past but nothing this dramatic.
0

Share this post


Link to post
Share on other sites
I found this (http://www.flipcode.com/archives/DirectInput_Example.shtml) with a comment that suggests releases are not buffered:

[code]if ((key_pressed[0].dwData & 0x80) ? 1 : 0) // only key-down events are reported
{
keyevent[key_pressed[0].dwOfs] = true;
}[/code]

Which seems to be directly contradicted by this (http://msdn.microsoft.com/en-us/library/windows/desktop/ee416238%28v=vs.85%29.aspx) quoted below because microsoft.com links have a very short shelf life...

[quote=Buffered Keyboard Data]o retrieve buffered data from the keyboard, you must first set the buffer size (see Device Properties). This step is essential because the default size of the buffer is 0.

You must also declare an array of DIDEVICEOBJECTDATA structures. This array can have up to the same number of elements as the buffer size. You do not have to retrieve the entire contents of the buffer with a single call. You can have just one element in the array and retrieve events one at a time until the buffer is empty.

After acquiring the keyboard device, you can examine and flush the buffer at any time by using the IDirectInputDevice8::GetDeviceData method. (See Buffered and Immediate Data.)

Each element in the DIDEVICEOBJECTDATA array represents a change in state for a single key-that is, a press or release. Because Microsoft DirectInput gets the data directly from the keyboard, any settings for character repeat in Control Panel are ignored. This means that a keystroke is counted only once, no matter how long the key is held down.

You can determine which key an element in the array refers to by checking the dwOfs member of the DIDEVICEOBJECTDATA structure against the DirectInput Keyboard Device. (See also Interpreting Keyboard Data.)

[b]The data for the change of state of the key is located in the dwData member of the DIDEVICEOBJECTDATA structure. Only the low byte of dwData is significant. The high bit of this byte is set if the key was pressed, and it is clear if it was released. In other words, the key was pressed if (dwData & 0x80) is nonzero.[/b][/quote]

I don't know why the world puts up with such a ghetto corporation. Oh yeah all of the others make the MS look like a saint nowadays and non-corporations don't have an advertising budget :(

Any ideas?
0

Share this post


Link to post
Share on other sites
In my opinion there is no contradiction here. The MSDN is quite specific about how the dwData should be interpreted.

The code you presented works as described = only key-down events are reported. Why is that? Because "(key_pressed[0].dwData & 0x80) ? 1 : 0" results as 0 when the key is released which is also equal to if(0), which means that your code isn't run when the key is released.

I think that there is a logical flaw in your code.

Best regards!
0

Share this post


Link to post
Share on other sites
^Hi, actually that's not my code. But if you do the experiment you will find that the condition in it is never false. I think the comment is just announcing the expected behavior. I could be wrong but the down events also appear to repeat. Which seems really counter to how DirectInput should work as there is nothing "direct" about translated input.

It seems like the person (lets give MS the benefit of doubt) who programmed the buffered side of the system keyboard device was just a world class twit and MS in its supreme irresponsibility never fixed it.

At any rate I describe a fix here ([url="http://xboxforums.create.msdn.com/forums/t/108722.aspx"]http://xboxforums.cr...s/t/108722.aspx[/url]) that basically just fills a buffer with the downed keys and calls GetAsyncKeyState until the key is lifted. In theory a down event could get timestamped before a previous up event (especially with the repeating behavior; though you could overwrite the timestamps too) but other than that its not so awful for buffered keyboard input. And its the only non-trivial specialization I had to do with for a system that exposes controllers as completely abstract beasts. In theory I could finish Super Mario Bros. with the nobs and mute button on a little speaker I have that for some reason shows up as a Direct Input controller. It was really annoying having to setup a DIK to VK translation table though.

If you are implementing input handlers on a subsystem basis you really don't have to pick a subsystem. It's probably the best that can be done for Direct Input and probably should work without a hitch if the buffer readback loop is of sufficient resolution. In other words there are plans to offer end users more than one keyboard option in my case. Edited by Mick is Stumped
0

Share this post


Link to post
Share on other sites
Ok faithful readers and anyone in the same boat....

Over in the xna forums (http://xboxforums.create.msdn.com/forums/p/108722/642144.aspx#642144) we discovered this behavior is caused by calling Unacquire in your event processing loop. Funnily enough only the keyboard seems to be affected.

Now if I could just figure out what the hell Acquire and Unacquire really do.

Sorry about the cross posting btw. Just doubles the odds of some one int a pinch finding this I guess [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]

Microsoft's sites are notoriously impermanent after all [img]http://public.gamedev.net//public/style_emoticons/default/dry.png[/img]
0

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  
Followers 0