Skip to content

Commit

Permalink
SnapKey.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cafali authored Aug 20, 2024
1 parent 8da2dff commit ff7e97b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion SnapKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using namespace std;
#define ID_TRAY_EXIT_CONTEXT_MENU_ITEM 3000
#define ID_TRAY_VERSION_INFO 3001
#define ID_TRAY_REBIND_KEYS 3002
#define ID_TRAY_LOCK_FUNCTION 3003
#define WM_TRAYICON (WM_USER + 1)

struct KeyState
Expand All @@ -34,6 +35,7 @@ unordered_map<int, KeyState> KeyInfo;
HHOOK hHook = NULL;
HANDLE hMutex = NULL;
NOTIFYICONDATA nid;
bool isLocked = false; // Variable to track the lock state

// Function declarations
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
Expand Down Expand Up @@ -193,7 +195,7 @@ void SendKey(int targetKey, bool keyDown)

LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
if (!isLocked && nCode >= 0)
{
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
if (!isSimulatedKeyEvent(pKeyBoard -> flags)) {
Expand Down Expand Up @@ -262,6 +264,8 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
HMENU hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, ID_TRAY_REBIND_KEYS, TEXT("Rebind Keys"));
AppendMenu(hMenu, MF_STRING, ID_TRAY_VERSION_INFO, TEXT("Version Info"));
AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hMenu, MF_STRING | (isLocked ? MF_CHECKED : MF_UNCHECKED), ID_TRAY_LOCK_FUNCTION, TEXT("Disable SnapKey"));
AppendMenu(hMenu, MF_STRING, ID_TRAY_EXIT_CONTEXT_MENU_ITEM, TEXT("Exit SnapKey"));

// Display the context menu
Expand All @@ -288,6 +292,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
ShellExecute(NULL, TEXT("open"), TEXT("config.cfg"), NULL, NULL, SW_SHOWNORMAL);
}
break;
case ID_TRAY_LOCK_FUNCTION:
{
isLocked = !isLocked;
// Update the context menu item to reflect the new lock state
HMENU hMenu = GetSubMenu(GetMenu(hwnd), 0);
CheckMenuItem(hMenu, ID_TRAY_LOCK_FUNCTION, MF_BYCOMMAND | (isLocked ? MF_CHECKED : MF_UNCHECKED));
}
break;
}
break;

Expand Down

0 comments on commit ff7e97b

Please sign in to comment.