Hi!
My class DXKeyboard has a method to check wether a key is pressed or not:
bool KeyPressed(int key). Now you can use this method like this:
if(instance.KeyPressed(DIK_A))
// do something.
This works fine, but now im trying to find out which key was pressed after the last GetDeviceState()-Update.
My idea:
GetDeviceState() stores data in a bool array[256]. For example, if the key "A" is pressed, array[65] gets the value true, because A = 65.
In addition to that, I know that the keyboard bus has a size of 8 Bit, this means only one key can be pressed at the same time.
So I wrote this method:
char DXKeyboard::KeyPressed()
{
for(int i=0; i<256; ++i)
{
if(m_Keystates)
{
ofstream key("key.txt", ios::app);
key<<"m_Keystates["<<i<<"] = "<<(bool)m_Keystates<<", char: "<<static_cast<char>(i)<<endl;
return(static_cast<char>(i)); // Convert i to the character...
}
}
return(0);
}
In my opinion this method should work perfect, but when I type "abcd" the file output is
Quote:
m_Keystates[30] = 128, char:
m_Keystates[48] = 128, char: 0
m_Keystates[46] = 128, char: .
m_Keystates[32] = 128, char:
Whats wrong?!