Wish: Live Keyboard Input capture

What:
a Node that when selected captures all keyboard inputs and outputs them as a List of values. It should capture all cursor keys, alt shift etc.
Not sure what the best output format is, but it should be able to handle multiple simultaneous hits.
Comparable how game engines handle input.

Why:
often processes / simulations run in real-time with the timer component, and live interaction is limited to sliders etc. or manipulating input geometry. I think this proposed node would be helpful for fast interaction / reaction.

Also we could finally code and play Tetris, Pacman and all the other games directly in GH! :slight_smile:

Edit: further down is a GH component that does this (not clean, but working)

To get data into a GH network though it would require the solution is expired on every keydown/keyup event. Unless the key watcher component piggy-backs on existing solutions and only outputs its new set of key states every time a solution runs anyway.

What sort of output would you like to see? Just a list of all keys currently pressed? A full history of keydown+keyup events since some t=0 mark? Changes to key states since the last solution?

i think it should only output when the solution runs (e.g. timer) and one state per key, no recording - this can be done externally. Basically the same behavior as most realtime engines: if a key is pressed during a frame (off-on or off-on-off) it counts as pressed for the next frame.
So no persistent data, no events. Oldschool…

Output format: List of something… maybe unicode + https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes
not sure how well hex values work with c#…

Okay, it’s logged under RH-47396 for future versions.

Note that old style key checking didn’t have concepts of off-on or on-off. They were either pressed or not. Down and up triggers were generally inferred internally.

that is what i meant - no triggers, but accumulation buffers: if a key is pressed for 10 ms and the refresh time of the solution is 60ms it will still register

That requires handling the key events, which is not really possible to do system wide, at least not without a lot of OS-specific hacking, and I have no idea whether it’s even possible on Mac at all.

I assume that on both Windows and Mac it is possible to query the state of all the keys at a specific moment and figure out which ones are in a down state.

For games you hardly ever want accumulation buffers. If you have a keypress that is shorter than the handling of a frame (solution) it just won’t register - if a key is pressed and released during the drawing of a frame before input handling happens it just simply never happened.

i was just thinking because the ‘frametimes’ in GH tend to be much longer than in a 60fps environment… but yes - its not necessary.

So i made a temporary solution:

KeyCapture.gh (5.9 KB)

This works as a c# node in GH, Run and Stop toggle a winform panel.
It accumulates key-presses, so with a timer set to 1 second it registers all key-presses in between.
Downside is that the little winform has to have focus.

@DavidRutten basically this, minus the need for a winform. Instead having the component selected gives it the focus?