-
Notifications
You must be signed in to change notification settings - Fork 19
Keyboard input support #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If your backend exposes it, allowing a key to be retrieved by either name ("a" maps to "a" on azerty, usecase: press "n" to toggle normals) or position ("a" maps to "q" on azerty, usecase: wasd movements) would be a huge upgrade for non-qwerty users :) In js I think it's done by comparing to either Name survey:
-> we could call that |
Slang playground should support keyboard input in addition to its mouse input.
Prior Work
Shadertoy
Allows keyboard input in a 256x3 uint8 input sampler. Each x coordinate represents the state of a different key. Y=0 represents the state of the key, Y=1 represents whether the key was pressed this frame, and Y=2 represents a toggle for that button.
Compute.toys
Allows keyboard input via a function
keyDown(keycode: u32)
. Internally this accesses a bit in avec4<u32>[2]
which compactly holds the state of the keys.Slang Native Playground
Allows keyboard input through a
playground::KEY_INPUT
user attribute on a float uniform. This takes the name of a key(ex. "space") and sets the uniform to 1.0 if the key is down and 0.0 otherwise. This is the least memory efficient if you are accessing many keys, but the most readable as it doesn't require memorizing key codes. It is also more memory efficient if the user uses less than 8 keys, which is common. However, it makes accessing keys dynamically much harder.Proposal
I suggest implementing the
playground::KEY_INPUT
solution for now, with the possibility of a bitfield in the future.The text was updated successfully, but these errors were encountered: