Skip to content

Commit

Permalink
introduce the ability to modify the hotkey
Browse files Browse the repository at this point in the history
* also, I've discovered that I can manually edit resource files.
  • Loading branch information
alzwded committed Nov 9, 2014
1 parent dd0b6b1 commit f8d1da8
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
94 changes: 92 additions & 2 deletions AltTabber/AltTabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ struct {
signed long activeSlot;
BOOL logging;
FILE* freopened;
struct {
UINT modifiers;
UINT key;
} hotkey;

HWND hWnd;
std::map<HMONITOR, std::vector<AppThumb_t> > thumbnails;
std::vector<SlotThing_t> slots;
Expand All @@ -63,6 +68,7 @@ struct {
-1,
FALSE,
NULL,
{ MOD_ALT | MOD_CONTROL, '3' },
};

// Global Variables:
Expand Down Expand Up @@ -252,6 +258,88 @@ static MonitorGeom_t GetMonitorGeometry()
return ret;
}

void SynchronizeWithRegistry()
{
#define SUBKEY (_T("Software\\jakkal\\AltTabber"))
HKEY phk = NULL;
DWORD disposition = 0;
auto hr = RegCreateKeyEx(HKEY_CURRENT_USER,
SUBKEY,
0,
NULL,
0,
KEY_READ | KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WRITE,
NULL,
&phk,
&disposition);

if(hr != ERROR_SUCCESS) {
log(_T("RegCreateKey failed %d: errno: %d\n"), hr, GetLastError());
return;
}

DWORD dModifiers = (DWORD)g_programState.hotkey.modifiers;
DWORD dKey = (DWORD)g_programState.hotkey.key;
DWORD dSize = sizeof(DWORD);

switch(disposition) {
case REG_CREATED_NEW_KEY: {
// set default values
hr = RegSetValueEx(phk,
_T("modifiers"),
0,
REG_DWORD,
(BYTE*)&dModifiers,
sizeof(DWORD));
if(hr != ERROR_SUCCESS) {
log(_T("RegSetValue failed %d: errno %d\n"), hr, GetLastError());
goto finished;
}
hr = RegSetValueEx(phk,
_T("key"),
0,
REG_DWORD,
(BYTE*)&dKey,
sizeof(DWORD));
if(hr != ERROR_SUCCESS) {
log(_T("RegSetValue failed %d: errno %d\n"), hr, GetLastError());
goto finished;
}
break; }
case REG_OPENED_EXISTING_KEY:
// read values
dSize = sizeof(DWORD);
hr = RegQueryValueEx(phk,
_T("modifiers"),
0,
NULL,
(BYTE*)&dModifiers,
&dSize);
if(hr != ERROR_SUCCESS) {
log(_T("RegQueryValue failed %d: errno %d\n"), hr, GetLastError());
goto finished;
}
dSize = sizeof(DWORD);
hr = RegQueryValueEx(phk,
_T("key"),
0,
NULL,
(BYTE*)&dKey,
&dSize);
if(hr != ERROR_SUCCESS) {
log(_T("RegQueryValue failed %d: errno %d\n"), hr, GetLastError());
goto finished;
}

g_programState.hotkey.modifiers = (UINT)(ULONG)dModifiers;
g_programState.hotkey.key = (UINT)(ULONG)dKey;
break;
}

finished:
RegCloseKey(phk);
}

//
// FUNCTION: InitInstance(HINSTANCE, int)
//
Expand Down Expand Up @@ -291,11 +379,13 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);

SynchronizeWithRegistry();

if(RegisterHotKey(
hWnd,
1,
MOD_ALT | MOD_CONTROL,
'3'))
g_programState.hotkey.modifiers,
g_programState.hotkey.key))
{
log(_T("win+caps registered\n"));
}
Expand Down
Binary file modified AltTabber/AltTabber.rc
Binary file not shown.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ The keys and functionality:
| start/stop logging | `F2` | this is a debug log; it writes it somewhere in `%TEMP%` in a file with a name like `alt????.tmp` |
| search | any printable characters | starts filtering the windows by name and/or image path in order to help find your window |

Changing the hotkey
-------------------

The hotkey can be changed from `Ctrl`-`Alt`-`3` by going in the registry under `HKEY_CURRENT_USER\Software\jakkal\AltTabber` and modifying the `modifiers` and `key` values.

The `modifiers` value is a combination of [the values described for fsModifeirs here](http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309.aspx) things.

The `key` value is one of [these](http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731.aspx) things.

If you mess something up, just delete the `HKEY_CURRENT_USER\Software\jakka\AltTabber` key and the app will make sure to recreate it again from defaults.

Disclaimer
==========

Expand Down

0 comments on commit f8d1da8

Please sign in to comment.