Skip to content
Prev 1054 / 1236 Next

[R-gui] Ask for the State of a Keyboard Key

Using Tk you can use the tkbind function to bind a keypress and/or keyrelease to run a function.  The usual mode is to have that function do whatever you plan, but you could have the keypress function update a list of keys currently pressed and the keyrelease function clear that key from the list, then your isKeyPressed function could just check to see if that key is in the list of currently pressed keys.

The playSudoku function in the sudoku package is one example of binding keys, you can look at the code for an example.

Note:  I think that the argument to the function you create/call is important in the Tk bindings.