diff --git a/src/res/qml/UtilitiesPage.qml b/src/res/qml/UtilitiesPage.qml index 5a575ee..76841cf 100644 --- a/src/res/qml/UtilitiesPage.qml +++ b/src/res/qml/UtilitiesPage.qml @@ -45,7 +45,7 @@ MyStackViewPage { MyPushButton { text: "Keyboard Input" - Layout.preferredWidth: 250 + Layout.preferredWidth: 200 onClicked: { OverlayController.showKeyboard("", 601) } @@ -61,15 +61,23 @@ MyStackViewPage { MyPushButton { text: "Enter" - Layout.preferredWidth: 250 + Layout.preferredWidth: 200 onClicked: { UtilitiesTabController.sendKeyboardEnter() } } + MyPushButton { + text: "Alt-Tab" + Layout.preferredWidth: 200 + onClicked: { + UtilitiesTabController.sendKeyboardAltTab() + } + } + MyPushButton { text: "Backspace" - Layout.preferredWidth: 250 + Layout.preferredWidth: 200 onClicked: { UtilitiesTabController.sendKeyboardBackspace(1) } @@ -77,7 +85,7 @@ MyStackViewPage { MyPushButton { text: "10x Backspace" - Layout.preferredWidth: 250 + Layout.preferredWidth: 200 onClicked: { UtilitiesTabController.sendKeyboardBackspace(10) } diff --git a/src/tabcontrollers/KeyboardInput.h b/src/tabcontrollers/KeyboardInput.h index 28c2468..05fcfc0 100644 --- a/src/tabcontrollers/KeyboardInput.h +++ b/src/tabcontrollers/KeyboardInput.h @@ -16,6 +16,7 @@ public: virtual void sendKeyboardInput(QString input) = 0; virtual void sendKeyboardEnter() = 0; virtual void sendKeyboardBackspace(int count) = 0; + virtual void sendKeyboardAltTab() = 0; }; } diff --git a/src/tabcontrollers/UtilitiesTabController.cpp b/src/tabcontrollers/UtilitiesTabController.cpp index 0ca7744..4cd203e 100644 --- a/src/tabcontrollers/UtilitiesTabController.cpp +++ b/src/tabcontrollers/UtilitiesTabController.cpp @@ -61,6 +61,10 @@ namespace advsettings { keyboardInput->sendKeyboardEnter(); } + void UtilitiesTabController::sendKeyboardAltTab() { + keyboardInput->sendKeyboardAltTab(); + } + void UtilitiesTabController::sendKeyboardBackspace(int count) { keyboardInput->sendKeyboardBackspace(count); } diff --git a/src/tabcontrollers/UtilitiesTabController.h b/src/tabcontrollers/UtilitiesTabController.h index 22e2f63..29d24e6 100644 --- a/src/tabcontrollers/UtilitiesTabController.h +++ b/src/tabcontrollers/UtilitiesTabController.h @@ -59,6 +59,7 @@ namespace advsettings { public slots: void sendKeyboardInput(QString input); void sendKeyboardEnter(); + void sendKeyboardAltTab(); void sendKeyboardBackspace(int count); void setAlarmEnabled(bool enabled, bool notify = true); diff --git a/src/tabcontrollers/keyboardinput/KeyboardInputDummy.cpp b/src/tabcontrollers/keyboardinput/KeyboardInputDummy.cpp index f0ab55b..69054a9 100644 --- a/src/tabcontrollers/keyboardinput/KeyboardInputDummy.cpp +++ b/src/tabcontrollers/keyboardinput/KeyboardInputDummy.cpp @@ -17,4 +17,9 @@ void KeyboardInputDummy::sendKeyboardBackspace(int count) // noop } +void KeyboardInputDummy::sendKeyboardAltTab() +{ + // noop +} + } diff --git a/src/tabcontrollers/keyboardinput/KeyboardInputDummy.h b/src/tabcontrollers/keyboardinput/KeyboardInputDummy.h index 53b651c..f5ee302 100644 --- a/src/tabcontrollers/keyboardinput/KeyboardInputDummy.h +++ b/src/tabcontrollers/keyboardinput/KeyboardInputDummy.h @@ -12,6 +12,7 @@ public: virtual void sendKeyboardInput(QString input) override; virtual void sendKeyboardEnter() override; virtual void sendKeyboardBackspace(int count) override; + virtual void sendKeyboardAltTab() override; }; } diff --git a/src/tabcontrollers/keyboardinput/KeyboardInputWindows.cpp b/src/tabcontrollers/keyboardinput/KeyboardInputWindows.cpp index dfa1518..aafa129 100644 --- a/src/tabcontrollers/keyboardinput/KeyboardInputWindows.cpp +++ b/src/tabcontrollers/keyboardinput/KeyboardInputWindows.cpp @@ -17,6 +17,24 @@ void fillKiStruct(INPUT& ip, WORD scanCode, bool keyup) { ip.ki.time = 0; }; +void sendKeyboardInputRaw(int inputCount, LPINPUT input) { + if (!SendInput(inputCount, input, sizeof(INPUT))) { + char *err; + auto errCode = GetLastError(); + if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language + (LPTSTR)&err, + 0, + NULL)){ + LOG(ERROR) << "Error calling SendInput(): Could not get error message (" << errCode << ")"; + } else { + LOG(ERROR) << "Error calling SendInput(): " << err; + } + } +} + void KeyboardInputWindows::sendKeyboardInput(QString input) { int len = input.length(); @@ -69,21 +87,8 @@ void KeyboardInputWindows::sendKeyboardInput(QString input) fillKiStruct(ips[ii++], VK_MENU, true); altPressed = false; } - if (!SendInput(ii, ips, sizeof(INPUT))) { - char *err; - auto errCode = GetLastError(); - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language - (LPTSTR)&err, - 0, - NULL)){ - LOG(ERROR) << "Error calling SendInput(): Could not get error message (" << errCode << ")"; - } else { - LOG(ERROR) << "Error calling SendInput(): " << err; - } - } + + sendKeyboardInputRaw(ii, ips); delete ips; } } @@ -93,21 +98,8 @@ void KeyboardInputWindows::sendKeyboardEnter() LPINPUT ips = new INPUT[2]; fillKiStruct(ips[0], VK_RETURN, false); fillKiStruct(ips[1], VK_RETURN, true); - if (!SendInput(2, ips, sizeof(INPUT))) { - char *err; - auto errCode = GetLastError(); - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language - (LPTSTR)&err, - 0, - NULL)) { - LOG(ERROR) << "Error calling SendInput(): Could not get error message (" << errCode << ")"; - } else { - LOG(ERROR) << "Error calling SendInput(): " << err; - } - } + + sendKeyboardInputRaw(2, ips); delete ips; } @@ -119,23 +111,23 @@ void KeyboardInputWindows::sendKeyboardBackspace(int count) fillKiStruct(ips[2 * i], VK_BACK, false); fillKiStruct(ips[2 * i + 1], VK_BACK, true); } - if (!SendInput(2 * count, ips, sizeof(INPUT))) { - char *err; - auto errCode = GetLastError(); - if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language - (LPTSTR)&err, - 0, - NULL)) { - LOG(ERROR) << "Error calling SendInput(): Could not get error message (" << errCode << ")"; - } else { - LOG(ERROR) << "Error calling SendInput(): " << err; - } - } + + sendKeyboardInputRaw(count * 2, ips); delete ips; } } +void KeyboardInputWindows::sendKeyboardAltTab() +{ + LPINPUT ips = new INPUT[4]; + // VK_MENU is alt + fillKiStruct(ips[0], VK_MENU, false); + fillKiStruct(ips[1], VK_TAB, false); + fillKiStruct(ips[2], VK_TAB, true); + fillKiStruct(ips[3], VK_MENU, true); + + sendKeyboardInputRaw(4, ips); + delete ips; +} + } diff --git a/src/tabcontrollers/keyboardinput/KeyboardInputWindows.h b/src/tabcontrollers/keyboardinput/KeyboardInputWindows.h index 70318a5..3292b72 100644 --- a/src/tabcontrollers/keyboardinput/KeyboardInputWindows.h +++ b/src/tabcontrollers/keyboardinput/KeyboardInputWindows.h @@ -12,6 +12,7 @@ public: virtual void sendKeyboardInput(QString input) override; virtual void sendKeyboardEnter() override; virtual void sendKeyboardBackspace(int count) override; + virtual void sendKeyboardAltTab() override; }; }