My question is about how I am handling input. Right now I fire an event to my character system telling it to move the character every time a keypress is detected. This works great for one key being held down. It also works for two keys being held down. However once I let go of the second key while the first key is still held down, GLFW stops calling back my keypress call back function each frame until I let go of the key that is held down.
Example:
0 seconds -
Hold W key to
start walking forward
keypress function is called back,
w has a value of 1
5 seconds -
W key is still held down
still walking forward
keypress function is called back,
w has a value of 1
10 seconds-
W key is still down, now hold Left Shift Key down
still walking forward, but now at 2x speed because of the shift key being down
keypress function is called back
w has value of 1, shift has value of 1
15 seconds -
W key is still down, let go of the shift key -
no longer moving forward
keypress function is called back
w has value of 1, shift has value of 0 - indicating key was let go
15.1 seconds
W key has been down the whole time
no movement since letting go of the shift key
no callbacks on my keypress function
20 seconds
W key has been down the whole time
no movement since letting go of the shift key
no callbacks on my keypress function
25 seconds
let go of W key
keypress function is called back
w key has a value of 0 - indicating key was let go
Below is some code from my callback function that GLFW calls on a keypress:
void GLFWCALL OnKeyPress(int key, int action)
{
if(glfwGetKey(GLFW_KEY_LSHIFT) )
{
eventData data(eventType::CHAR_SPRINT, moveableCharacter);
EventSystem->TriggerEvent(eventType::CHAR_SPRINT, &data);
}
if(glfwGetKey('W') )
{
eventData data(eventType::CHAR_FORWARD, moveableCharacter);
EventSystem->TriggerEvent(eventType::CHAR_FORWARD, &data);
}
// ... more of the same
}
First, is this how GLFW is supposed to work and am I going about this all wrong? Should I be manipulating the character through triggering events or should I have a character state that gets altered by the events such as WALKING, IDLE, RUNNING, etc... Or, is this a bug in GLFW?
TLDR: GLFW reports a keypress event for the W key each frame it is held down until I press a second key while still holding W down. A keypress event is reported when I let go of the key but nothing happens in between.
Thanks for looking at this!