   Effectively using DirectInput
  I''m trying to make some gui code and I want to use DirectInput. My problem is that I don''t know how to use it effectively. Right now, I have a statement like this for the keys:   if(Engine.Keyboard.KeyDown(DIK_A){if(Engine.Keyboard.KeyDown(LSHIFT) || Engine.Keyboard.KeyDown(LSHIFT)){GuiControl.AddCharacter(''A'');}else{GuiControl.AddCharacter(''a'');}}// Isn''t there a way that I can do what I did in my WndProcGuiControl.AddCharacter(wParam - ALPHABET_MODIFIER);And this isn''t very organized. Second, If I hit a key, it gets added three or four times. I don''t know if I''m doing something wrong or what, I''d like to know. Thanks!   /*I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)*/ 
  You need to build your own delays in to stop the repeating keys - dinput is very fast so put a timer in that defines the gap between key presses. You can also put one in for a repeat delay - if someone holds the same key down for a certain time it should repeat. Its just like you can define in windows. Also remember to clear the key array each time! ;  You''ll want to add a debounce to key presses, store the previous frames key states and check if the key was pressed the frame before and only add it if it wasn''t.  Alternativly you could add a timer and only add the second character after a delay.;  I would also use some simple logic to chage the characters to lowercase if the shift is down. Just OR 64 into the uppercase character to produce the lowercase equivalent. Well, at least it is that simple for the english alphabet. Otherwise to support localization, you would need to request more help from the Win32 API to convert directinput key scan codes to the corresponding Unicode character. Because of this difficulty, when handling text input, I simply fall back to handling WM_CHAR messages, which is much easier as the input is already localized. ;  Alright, thanks. That''s what I''ve been doing (using Win32) so I guess I''ll stick with that. Thanks for helping guys.@Trip99: To clear the array, I just use ZeroMemory(&m_Keys, sizeof(char[256])) right?@Kafeen: Do you mean instead of using one char[256] do this:char m_PrevKeys[256];char m_Keys[256];Then have a swapping function and call that every frame before I check input? Thanks again!   /*I use DirectX 8.1 and C++ (Microsoft Visual C++ 6.0 Professional edition)*/ ;  Yes but it is not always correct to say that since the key was held down last time it is not to be registered this time as the user may be trying to enter two letters the same so you need to trap that case with a key repeat delay 