zzoru wrote:Alberth wrote:Why not make a patch that extends the hotkeys file?
That is one of my todo list.
I think that this patch is a fastest(also, easiest) way to apply wasd keys for scrolling mainview.
and also It seems that OpenTTD hotkey system doesn't completely support simultaneous alphabet key input now (Hotkey system needs to support it because of scrolling upleft, upright, etc...), isn't it? (I make some codes for testing this.)
I make sample code using hotkey system.
src/video/cocoa/event.mm
Code: Select all
static Hotkey test_hotkeys[] = {
Hotkey('W', "scroll_up", GHK_SCROLL_UP),
Hotkey('S', "scroll_down", GHK_SCROLL_DOWN),
Hotkey('A', "scroll_left", GHK_SCROLL_LEFT),
Hotkey('D', "scroll_right", GHK_SCROLL_RIGHT),
HOTKEY_LIST_END
};
HotkeyList *hotkeys = new HotkeyList("test", test_hotkeys);
static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL down)
{
bool interpret_keys = true;
int hotkey = hotkeys->CheckMatch(QZ_MapKey(keycode));
switch (hotkey) {
case GHK_SCROLL_UP: SB(_dirkeys, 1, 1, down); break;
case GHK_SCROLL_DOWN: SB(_dirkeys, 3, 1, down); break;
case GHK_SCROLL_LEFT: SB(_dirkeys, 0, 1, down); break;
case GHK_SCROLL_RIGHT: SB(_dirkeys, 2, 1, down); break;
}
switch (keycode) {
case QZ_TAB: _tab_is_down = down; break;
case QZ_RETURN:
case QZ_f:
if (down && (_current_mods & NSCommandKeyMask)) {
VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
}
break;
case QZ_v:
if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
HandleKeypress(WKC_CTRL | 'V', unicode);
}
break;
case QZ_u:
if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
HandleKeypress(WKC_CTRL | 'U', unicode);
}
break;
}
It works well, but it isn't clean code. I think that hotkey must be handled by OnHotKey API.
but, OnHotKey API can't handle simultaneous key input
