Skip to content

Commit f6cbbc9

Browse files
committed
feat: reverse cycle when holding shift
fix #16
1 parent f439ec5 commit f6cbbc9

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

AltBacktick.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ int StartBackgroundApp() {
9494
}
9595
}
9696

97+
int reverseHotkeyId = 1;
98+
if (!RegisterHotKey(NULL, reverseHotkeyId, modifierKey | MOD_SHIFT, keyCode)) {
99+
DWORD lastError = GetLastError();
100+
if (lastError == ERROR_HOTKEY_ALREADY_REGISTERED) {
101+
MessageBox(
102+
NULL, L"Failed to register the reverse hotkey.\nMake sure no other application is already binding to it.",
103+
L"Failed to register reverse hotkey", MB_ICONEXCLAMATION);
104+
return 0;
105+
}
106+
}
107+
97108
HHOOK keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHook, 0, 0);
98109
if (keyboardHook == NULL) {
99110
MessageBox(NULL, L"Failed to register keyboard hook.", L"Error", MB_ICONEXCLAMATION);
@@ -136,10 +147,20 @@ int StartBackgroundApp() {
136147
if (mru.empty()) {
137148
continue;
138149
}
139-
if (mru.begin() + offset + 1 < mru.end()) {
140-
offset++;
150+
151+
bool isReverseDirection = msg.wParam == reverseHotkeyId;
152+
if (isReverseDirection) {
153+
if (offset > 0) {
154+
offset--;
155+
} else {
156+
offset = mru.size() - 1;
157+
}
141158
} else {
142-
offset = 0;
159+
if (mru.begin() + offset + 1 < mru.end()) {
160+
offset++;
161+
} else {
162+
offset = 0;
163+
}
143164
}
144165

145166
HWND windowToFocus = mru[offset];

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
`AltBacktick` is a small Windows program that runs in background and allows to switch between windows of the same program using the keyboard shortcut `ALT`+`` ` `` (the `ALT` key can be configured).
1+
`AltBacktick` is a small Windows program that runs in background and allows to switch between windows of the same program using the keyboard shortcut `ALT`+`` ` `` (the `ALT` key can be configured).
2+
To cycle through windows in reverse order, hold `SHIFT` while pressing the modifier key.
23

34
![AltBacktick](./demo.gif)
45

56
It's similar to [Easy Window Switcher](https://neosmart.net/EasySwitch/) but it supports more programs (for instance TablePlus), handles minimized windows and is open source.
67

7-
*The key `` ` `` (`backtick`) is above the `TAB` key on QWERTY keyboard but even if your keyboard is not QWERTY, the shortcut will be mapped to the key above the `TAB` key.*
8+
_The key `` ` `` (`backtick`) is above the `TAB` key on QWERTY keyboard but even if your keyboard is not QWERTY, the shortcut will be mapped to the key above the `TAB` key._
89

910
## Usage
1011

0 commit comments

Comments
 (0)