Note that there are some explanatory texts on larger screens.

plurals
  1. POHow I can prevent every key being sent to KeyboardUpFunc in GLUT?
    text
    copied!<p>I'm fairly new to OpenGL, and I am writing a simple game in 2D, for fun. However, I ran into an issue I am having a hard time wrapping my head around.</p> <p>It seems that whenever my keyboardUpFunc is called, that not only the key that has actually come up sent to the function, but every single key currently being pressed as well.</p> <p>I'm using a simple key buffer to manage the keys, keyUp marks the key as up and is only called in this function. keyDown is called in my keyboardFunc. isDown returns a boolean value of whether or not the key is pressed. Take this code for example:</p> <pre><code>#include &lt;iostream&gt; ... void keyboardUp(unsigned char key, int x, int y) { keys.keyUp(key); if (keys.isDown('s') == false) { std::cout &lt;&lt; "It's resetting s as well!" &lt;&lt; std::endl; } // reset acceleration here, for each key if ( (key == 'w') || (key == 's') ) { yStep = 0.1; } if ( (key == 'a') || (key == 'd') ) { xStep = 0.1; } std::cout &lt;&lt; key &lt;&lt; " is now up." &lt;&lt; std::endl; } </code></pre> <p>If you run this code, if you for example, hold S and D, then release the D key, you will note that S has been marked as up too, since this is the only location keyUp is being called.</p> <p>Assuming my keyBuffer code is working correctly (and it is, but let me know if you want me to post it...), is there any way to get around this? Where if you were holding a key, and then pressed another key, the application would go back to what you were doing when you were just holding the original key? Instead of marking both as up? Or is this not feasible with GLUT?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload