Hey everyone, I'm playing around with SFML in C# and am encountering a strange problem with the KeyPressed event where it fires once, then doesn't fire while I'm holding down the key until later.
When the KeyPressed event is fired, I set the value of the index of the corresponding key in an array to true and set the value of the previous pressed value to that value before (Ex. prevPressed[index] = pressed[index]; pressed[index] = true).
Here's some sample code (I have confirmed that I subscribed to the event only once in code not shown):
while (GameWindow.IsOpen)
{
//Process events
GameWindow.DispatchEvents();
//Update game logic here
gameCore.Update();
In gameCore.Update() all I have is this:
if (Input.PressedKey(Keyboard.Key.A))
Debug.Log("Pressed A!");
All the Input.PressedKey() method does is check if the previous state of the key wasn't pressed and the current state of the key is pressed, effectively checking if it was JUST pressed on that frame so we don't handle held input when not necessary. The first time I press the key, it acts like normal, but when I hold it I see a bunch of the "Pressed A!" logs and don't see the KeyPressed event getting fired again, halting the "Pressed A!" logs, until roughly 20 frames later. My framerate is capped at 60, but this occurs even if I don't set the limit. The KeyReleased event works as normal.
Any ideas? I have a temporary workaround that I'd rather not keep where I loop through the entire array (101 elements) each frame and set prevPressed[index] to pressed[index] after gameCore.Update().