Skip to main content
added 195 characters in body
Source Link
Katu
  • 2.1k
  • 1
  • 15
  • 19

Pseudo code:

currentKeyboardState
previousKeyboardState

void UpdateInput()
    store currentstate to previousstate
    get new state to currentstate

Now that we have stored the last state and we know the current state, we can check if key was NOT pressed in last frame and is now pressed. So we know if key was pressed down just now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && !previousKeyboardState.KeyIsPressed( KEY_B ))

We can also detect if key is being held down, by checking if it was down last frame and now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

Checking if key was down last frame, but is not anymore, we can say that it was released.

if(!currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

With these, i think you can create what you need.

TL;DR;

Store previous keyboard state, so you can compare current state to previous state and determine if something fishy is going on.

Pseudo code:

currentKeyboardState
previousKeyboardState

void UpdateInput()
    store currentstate to previousstate
    get new state to currentstate

Now that we have stored the last state and we know the current state, we can check if key was NOT pressed in last frame and is now pressed. So we know if key was pressed down just now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && !previousKeyboardState.KeyIsPressed( KEY_B ))

We can also detect if key is being held down, by checking if it was down last frame and now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

With these, i think you can create what you need.

TL;DR;

Store previous keyboard state, so you can compare current state to previous state and determine if something fishy is going on.

Pseudo code:

currentKeyboardState
previousKeyboardState

void UpdateInput()
    store currentstate to previousstate
    get new state to currentstate

Now that we have stored the last state and we know the current state, we can check if key was NOT pressed in last frame and is now pressed. So we know if key was pressed down just now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && !previousKeyboardState.KeyIsPressed( KEY_B ))

We can also detect if key is being held down, by checking if it was down last frame and now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

Checking if key was down last frame, but is not anymore, we can say that it was released.

if(!currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

With these, i think you can create what you need.

TL;DR;

Store previous keyboard state, so you can compare current state to previous state and determine if something fishy is going on.

Source Link
Katu
  • 2.1k
  • 1
  • 15
  • 19

Pseudo code:

currentKeyboardState
previousKeyboardState

void UpdateInput()
    store currentstate to previousstate
    get new state to currentstate

Now that we have stored the last state and we know the current state, we can check if key was NOT pressed in last frame and is now pressed. So we know if key was pressed down just now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && !previousKeyboardState.KeyIsPressed( KEY_B ))

We can also detect if key is being held down, by checking if it was down last frame and now.

if(currentKeyboardState.KeyIsPressed( KEY_B ) && previousKeyboardState.KeyIsPressed( KEY_B ))

With these, i think you can create what you need.

TL;DR;

Store previous keyboard state, so you can compare current state to previous state and determine if something fishy is going on.