Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput8 buffered mode

Started by DaveTheMan2000 Jan 24, 2003 at 11:42 PM 1 replies 400+ views
Original Post
DaveTheMan2000
DaveTheMan2000
I am trying to sort out how to do text input in my engine. I have two somewhat different requirements. 1) To have fast stateless input for character movement. 2) To have buffered input for the console I have written. For (1) I use DirectInput immediate mode, read the state of the keyboard once per frame and then I can just check the key state I am looking for - this works fine. For (2), I have DirectInput8 set up so that I can switch between immediate and buffered modes in my Input class. This also works fine, for the most part - but I can''t work out how to get modified characters! So, eg, in buffered mode I only get the character 9 instead of ( when holding down the SHIFT key. What I need to know, is whether buffered mode can be set to report modified keys like the shifted brackets etc, or if I will have to just use immediate mode and write my own buffering kind of system..?? How have other people done this? Also, please don''t suggest using the WM_* messages from the WndProc function - they are slow, messy to pass around between classes and not the way I want to do things... Thanks for any thoughts..
Krunk
Krunk
Unfortunately, DirectInput just treats the keyboard as a "102 button joypad" - it just tells you which buttons are pressed without combining them in the usual ways (like shift + 2 = "). I suppose you could monitor the shift keys yourself and combine inputs as appropriate. The problem is that although you can find out the localised key name, you have no way of knowing what characters should be produced for given combinations. For instance, pressing shift + 3 produces a £ on a UK keyboard, but on a US keyboard it produces a # (I think). That''s before you get into languages with accents (where "dead keys" are used).

This means you will either have to hardcode the keymap (which is very annoying if the keymap and keyboard don''t match) or find some way to interface with win32 keymapping to get the information you need from there. The other option, which you have already mentioned, is to find some way to route WM_CHAR or WM_KEYUP/DOWN into your input module. Not particularly the way I want to do things either, but that''s probably the best way to handle it at the moment.

I think there was supposed to be an updated version of DirectInput in which would help solve these sorts of problems, but it hasn''t showed up in DX9. Here''s hoping they finish it for DX10 .
neo_ryder
neo_ryder
well either you maintain a map yourself or use something like

short Ascii(uint scancode)
{
ushort ch;
int ret;

// keys is the 256 byte array that you pass to GetDeviceState, scancode is equivalent to DIK_* values

ret = ::ToAscii(MapVirtualKey(scancode, 1), scancode, keys, (LPWORD)&ch, 0);
if(ret > 1)
return ch;
else if (ret == 1)
return ch & 0xff;

return ret ? 0:scancode;
}

Topic Locked

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

Sign in to reply to this topic.