Key out of range
p0nce opened this issue · 4 comments
Hello,
Engine sounds very promising!
How to reproduce:
On Windows, when I press the Fn key, or the "sound mute" key on my keyboard, the engine closes with message:
core.exception.AssertError@source\hip\event\dispatcher.d(270): Key out of range
----------------
0x00007FF76476EB49 in d_assert_msg
0x00007FF76461CD9B in hip::event::dispatcher::getHipKeyFromSystem at C:\Users\guill\Desktop\HipremeEngine\source\hip\event\dispatcher.d(270)
0x00007FF76461C635 in hip::event::dispatcher::EventDispatcher::this::__lambda2 at C:\Users\guill\Desktop\HipremeEngine\source\hip\event\dispatcher.d(58)
0x00007FF76472C8CD in hip::windowing::platforms::windows::WndProc at C:\Users\guill\Desktop\HipremeEngine\modules\windowing\source\hip\windowing\platforms\windows.d(61)
0x00007FFB93B58231 in DispatchMessageW
0x00007FFB93B57A7B in CallWindowProcW
0x00007FFB825D1D74 in wglSwapBuffers
0x00007FFB93B58231 in DispatchMessageW
0x00007FFB93B57CF1 in DispatchMessageW
Expected behaviour: key being ignored instead of closing game.
So cannot hit F5 on that keyboard for now since I need Fn key
For the Fn key specifically:
- it has no scancode https://stackoverflow.com/questions/24423724/what-is-the-key-scan-code-of-the-fn-key-for-use-in-autohotkey-ahk
- keyboard hides it from the OS. If you press just "Fn", it sends 255 in Windows. Otherwise sends the code of a regular key.
- either we add a key HipKey.NO_MAPPING (or HipKey.NONE) when Fn is pressed alone (255)
- either a lonely press of Fn key is ignored, no callback
What do you think?
Arguably since a lot of key are incorrectly translated right now (cast), an unknown key should return a special value.
Interestingly enough, in my keyboard, Fn doesn't even generate an event. I believe that HipKey.NONE is nice.
I noticed also that the assert only check whether it is less, not less equal. I'm going to update that real quickly
The key should actually return the special value:
default:
version(HipCheckUnknownKeycode)
{
import hip.util.conv:to;
assert(false, "Unknown key received ("~to!string(k)~")");
}
else
return cast(HipKey)k;
The thing is that it was failing in the assert above because it didn't correctly check 0xFF