* Handle keyboard input. * @param keycode Virtual keycode of the key. * @param key Unicode character of the key. */
| 2651 | * @param key Unicode character of the key. |
| 2652 | */ |
| 2653 | void HandleKeypress(uint keycode, char32_t key) |
| 2654 | { |
| 2655 | /* World generation is multithreaded and messes with companies. |
| 2656 | * But there is no company related window open anyway, so _current_company is not used. */ |
| 2657 | assert(HasModalProgress() || IsLocalCompany()); |
| 2658 | |
| 2659 | /* |
| 2660 | * The Unicode standard defines an area called the private use area. Code points in this |
| 2661 | * area are reserved for private use and thus not portable between systems. For instance, |
| 2662 | * Apple defines code points for the arrow keys in this area, but these are only printable |
| 2663 | * on a system running OS X. We don't want these keys to show up in text fields and such, |
| 2664 | * and thus we have to clear the unicode character when we encounter such a key. |
| 2665 | */ |
| 2666 | if (key >= 0xE000 && key <= 0xF8FF) key = 0; |
| 2667 | |
| 2668 | /* |
| 2669 | * If both key and keycode is zero, we don't bother to process the event. |
| 2670 | */ |
| 2671 | if (key == 0 && keycode == 0) return; |
| 2672 | |
| 2673 | /* Check if the focused window has a focused editbox */ |
| 2674 | if (EditBoxInGlobalFocus()) { |
| 2675 | /* All input will in this case go to the focused editbox */ |
| 2676 | if (_focused_window->window_class == WC_CONSOLE) { |
| 2677 | if (_focused_window->OnKeyPress(key, keycode) == ES_HANDLED) return; |
| 2678 | } else { |
| 2679 | if (_focused_window->HandleEditBoxKey(_focused_window->nested_focus->GetIndex(), key, keycode) == ES_HANDLED) return; |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | /* Call the event, start with the uppermost window, but ignore the toolbar. */ |
| 2684 | for (Window *w : Window::IterateFromFront()) { |
| 2685 | if (w->window_class == WC_MAIN_TOOLBAR) continue; |
| 2686 | if (w->window_desc.hotkeys != nullptr) { |
| 2687 | int hotkey = w->window_desc.hotkeys->CheckMatch(keycode); |
| 2688 | if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return; |
| 2689 | } |
| 2690 | if (w->OnKeyPress(key, keycode) == ES_HANDLED) return; |
| 2691 | } |
| 2692 | |
| 2693 | Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
| 2694 | /* When there is no toolbar w is null, check for that */ |
| 2695 | if (w != nullptr) { |
| 2696 | if (w->window_desc.hotkeys != nullptr) { |
| 2697 | int hotkey = w->window_desc.hotkeys->CheckMatch(keycode); |
| 2698 | if (hotkey >= 0 && w->OnHotkey(hotkey) == ES_HANDLED) return; |
| 2699 | } |
| 2700 | if (w->OnKeyPress(key, keycode) == ES_HANDLED) return; |
| 2701 | } |
| 2702 | |
| 2703 | HandleGlobalHotkeys(key, keycode); |
| 2704 | } |
| 2705 | |
| 2706 | /** |
| 2707 | * State of CONTROL key has changed |
no test coverage detected