KeyEvent: Support modifiers / UI: Open file chooser on ctrl-O (#707)
* file chooser on ctrl-o * typo fix
This commit is contained in:
parent
8cf8707d4e
commit
8e1c0201ad
|
@ -88,6 +88,11 @@ bool EmulatorWindow::Initialize() {
|
|||
window_->on_key_down.AddListener([this](KeyEvent* e) {
|
||||
bool handled = true;
|
||||
switch (e->key_code()) {
|
||||
case 0x4F: { // o
|
||||
if (e->is_ctrl_pressed()) {
|
||||
FileOpen();
|
||||
}
|
||||
} break;
|
||||
case 0x6A: { // numpad *
|
||||
CpuTimeScalarReset();
|
||||
} break;
|
||||
|
|
|
@ -40,11 +40,17 @@ class FileDropEvent : public UIEvent {
|
|||
|
||||
class KeyEvent : public UIEvent {
|
||||
public:
|
||||
KeyEvent(Window* target, int key_code, int repeat_count, bool prev_state)
|
||||
KeyEvent(Window* target, int key_code, int repeat_count, bool prev_state,
|
||||
bool modifier_shift_pressed, bool modifier_ctrl_pressed,
|
||||
bool modifier_alt_pressed, bool modifier_super_pressed)
|
||||
: UIEvent(target),
|
||||
key_code_(key_code),
|
||||
repeat_count_(repeat_count),
|
||||
prev_state_(prev_state) {}
|
||||
prev_state_(prev_state),
|
||||
modifier_shift_pressed_(modifier_shift_pressed),
|
||||
modifier_ctrl_pressed_(modifier_ctrl_pressed),
|
||||
modifier_alt_pressed_(modifier_alt_pressed),
|
||||
modifier_super_pressed_(modifier_super_pressed) {}
|
||||
~KeyEvent() override = default;
|
||||
|
||||
bool is_handled() const { return handled_; }
|
||||
|
@ -55,12 +61,22 @@ class KeyEvent : public UIEvent {
|
|||
int repeat_count() const { return repeat_count_; }
|
||||
bool prev_state() const { return prev_state_; }
|
||||
|
||||
bool is_shift_pressed() const { return modifier_shift_pressed_; }
|
||||
bool is_ctrl_pressed() const { return modifier_ctrl_pressed_; }
|
||||
bool is_alt_pressed() const { return modifier_alt_pressed_; }
|
||||
bool is_super_pressed() const { return modifier_super_pressed_; }
|
||||
|
||||
private:
|
||||
bool handled_ = false;
|
||||
int key_code_ = 0;
|
||||
|
||||
int repeat_count_ = 0;
|
||||
bool prev_state_ = false; // Key previously down(true) or up(false)
|
||||
|
||||
bool modifier_shift_pressed_ = false;
|
||||
bool modifier_ctrl_pressed_ = false;
|
||||
bool modifier_alt_pressed_ = false;
|
||||
bool modifier_super_pressed_ = false;
|
||||
};
|
||||
|
||||
class MouseEvent : public UIEvent {
|
||||
|
|
|
@ -572,8 +572,10 @@ bool Win32Window::HandleMouse(UINT message, WPARAM wParam, LPARAM lParam) {
|
|||
}
|
||||
|
||||
bool Win32Window::HandleKeyboard(UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
auto e = KeyEvent(this, static_cast<int>(wParam), lParam & 0xFFFF0000,
|
||||
!!(lParam & 0x2));
|
||||
auto e = KeyEvent(
|
||||
this, static_cast<int>(wParam), lParam & 0xFFFF0000, !!(lParam & 0x2),
|
||||
!!(GetKeyState(VK_SHIFT) & 0x80), !!(GetKeyState(VK_CONTROL) & 0x80),
|
||||
!!(GetKeyState(VK_MENU) & 0x80), !!(GetKeyState(VK_LWIN) & 0x80));
|
||||
switch (message) {
|
||||
case WM_KEYDOWN:
|
||||
OnKeyDown(&e);
|
||||
|
|
Loading…
Reference in New Issue