-
Notifications
You must be signed in to change notification settings - Fork 11
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
OSX scan_code doesn't match other platforms #18
Comments
Another potential solution for this problem could be to have a different scan_to_code method for mac os. I think this would equate to about the same amount of work but would allow the removal of virtual key codes being sent in key up and key down events. |
yup that would work too! That fn is just crazy tedious to write and I lazy'd out and went with the universal fix |
If anyone wants the full vcode table as well, I dropped it here: https://zerobin.net/?7979275d556ac9dc#F8vc6C3kBGEmE4vdcC669DKHwp33qrgdW/hKGXEyznM= |
Ah this is great! Would you like to add this as a PR? |
I surely can, but I'm not certain it won't break anything. This was the first time I'd ever had OSX misbehave through winit, so I went to look at my old wgpu code and realized they use this virtual keycode instead of scancodes. I poked through winit just now and I believe it's basically doing the multiple scan_to_code per-OS internally and exposing the result via that virtual keycode. Their docs suggest winit's normally intended to be used via those virtuals instead: The winit docs also touch on it inside their KeyboardInput struct https://docs.rs/winit/0.24.0/winit/event/struct.KeyboardInput.html and I think also suggest we use VirtualKeyCode for this. I've tried it on Win 10/OSX/Manjaro and it seems to work just fine, but we could maybe leave every OS except mac on the current scan code impl? I'm just not sure what the smart safe answer is |
Update on this one, I went to double check with the Winit guys and they are right now finishing off a complete refactor of this system and said our code will need to change regardless soon. I think we probably want to just table this one for now until whatever winit does is done. Tracking meta issue for that is rust-windowing/winit#1806 |
Okay fair enough. Though since we don't know how long this will take it might be work just adding a quick fix just for mac os so that widgets receive the right virtual keycode. |
Yup rather than take a risk of breaking things, I can just drop my vcode table in for osx now and leave everything else the way it is until Winit's done? |
So in glutin's application.rs, the WindowEvent::KeyboardInput branch grabs the scancode from the input event and converts it to tuix event via scan_to_code(). Scan_to_code is broken for OSX because OSX maps its scan codes differently. Using the KeyZ example from the cpal tutorial, that scancode on osx isn't KeyZ, it's Digit5
Winit solves this by providing an alternative field on KeyboardInput, virtual_keycode, which can be mapped by all OSs instead.
Ex: in keyboard.rs, rather than scan_to_code, you can use a different transform fn like this
I haven't done the rest of the mappings yet because I'm not sure exactly how you want to approach this or what else it could break, but this fixes the synth example code specifically for KeyZ. Once we chat about it I'm happy to finish it off and PR
The text was updated successfully, but these errors were encountered: