After holding down a key and releasing it, GetRawKeyState will show the key has been released but on the next few cycles will again show the key has been pressed again. This causes my character in my game to continue walking for a few moments after releasing the movement keys. This issue only exists in Linux.
Here is a simple example that will demonstrate the problem. The example uses the arrow keys. It will show a history of key states. Adds a "O" to the key press history when a arrow key is held down and a "." when no arrow key is pressed.
This is in Tier 2.
// Includes
#include "template.h"
#include <string>
// Namespace
using namespace AGK;
using namespace std;
app App;
string sHistory = "....................................................................";
void app::Begin(void)
{
agk::SetVirtualResolution (1024, 768);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
}
int app::Loop (void)
{
agk::Print("Press and hold an arrow key for a few");
agk::Print("moments and then release.");
agk::Print(" ");
sHistory = sHistory.substr(0,30);
agk::Print(sHistory.c_str());
if (agk::GetRawKeyState(39))
{
sHistory = "O" + sHistory;
agk::Print("Right");
}
else if (agk::GetRawKeyState(38))
{
sHistory = "O" + sHistory;
agk::Print("Up");
}
else if (agk::GetRawKeyState(37))
{
sHistory = "O" + sHistory;
agk::Print("Left");
}
else if (agk::GetRawKeyState(40))
{
sHistory = "O" + sHistory;
agk::Print("Down");
}
else
{
sHistory = "." + sHistory;
}
agk::Sync();
return 0; // return 1 to close app
}
void app::End (void)
{
}