hiran wrote: ↑Tue Aug 03, 2021 7:31 pm
So my approach would be to eliminate the key='x' and key='X' completely and simply go by keycode=74, shift=true, leftCtrl=false
If that were the only style catered for, I think a normal player (without your experience with keyboard handling) would be rather put off by having to find the correct code for every entry. And we'd be adding explanatory comment lines to every entry explaining what the keycode translates to.
I think instead the goal I will aim for is to allow for either - if you want to use the character, put that in. If you want to use a keycode, put that in. At the moment, with the current keyconfig.plist file, that's what's happening internally anyway - characters are being replaced with the integer keycode value equivalent. One feature I'm planning on trying to implement is to allow for descriptive key names for special function keys, like "arrowLeft", "pageUp", "f3", "esc", that sort of thing, so that you don't have to have a keycode reference sheet handy any time you want to play around with your keyboard layout.
As for the leftCtrl/rightCtrl idea, what follows is a bit technical and relates to my current read of the source code (so I'm prepared to be told I have no clue about what I'm talking about!). There are two files in the core code that deal with keyboard handling. "src\SDL\MyOpenGLView.m" and "src\Cocoa\MyOpenGLView.m". I
think the "Cocoa" is a Mac-specific one, while the "SDL" version applies to Windows and Linux. In the "SDL" version, I can see some simple changes could be made to allow for the different versions of Ctrl and Alt to be visible to the rest of the game code.
But in the "Cocoa" version, there isn't a clear-cut distinction between the different sides. There is, instead, this:
Code: Select all
/* Capture shift, ctrl, opt and command press & release */
- (void)flagsChanged:(NSEvent *)theEvent
{
NSUInteger flags = [theEvent modifierFlags];
opt = (flags & NSAlternateKeyMask) ? YES : NO;
ctrl = (flags & NSControlKeyMask) ? YES : NO;
command = (flags & NSCommandKeyMask) ? YES : NO;
shift = ( flags & NSShiftKeyMask ) ? YES : NO;
if ([theEvent keyCode] == 0x39) // 57 = key code for caps lock
{
capsLockOn = (flags & NSAlphaShiftKeyMask) ? YES : NO;
}
}
"opt", "ctrl" and "command" are keyboard-side agnostic. And my quick scan of the Apple documentation doesn't give me a left/right option (in fact the current modifiers have even been deprecated in newer versions of Obj-C, by the look of it).
Is there a way around this? Probably. But I don't have a Mac, so I can't test any change and I'd be programming in the blind making wholesale changes to Mac-specific code.
So, given this code change is already going to be a stretch goal for me, I'm thinking I'll leave the left/right variations for a later date. I'll just try to make sure I leave room in my implementation for future changes that won't break what is there already.