This repository has been archived by the owner on Sep 6, 2020. It is now read-only.
forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
#include <Windows.h> | ||
|
||
namespace | ||
{ | ||
const wchar_t* ll_mouse = L"ll_mouse"; | ||
} | ||
|
||
struct LowlevelMouseEvent | ||
{ | ||
MSLLHOOKSTRUCT* lParam; | ||
WPARAM wParam; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "pch.h" | ||
#include "lowlevel_mouse_event.h" | ||
#include "powertoys_events.h" | ||
|
||
namespace | ||
{ | ||
HHOOK hook_handle = nullptr; | ||
HHOOK hook_handle_copy = nullptr; // Why should we use this in CallNextHookEx call? | ||
LRESULT CALLBACK hook_proc(int nCode, WPARAM wParam, LPARAM lParam) | ||
{ | ||
LowlevelMouseEvent event; | ||
if (nCode == HC_ACTION) | ||
{ | ||
event.lParam = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam); | ||
event.wParam = wParam; | ||
if (powertoys_events().signal_event(ll_mouse, reinterpret_cast<intptr_t>(&event)) != 0) | ||
{ | ||
return 1; | ||
} | ||
} | ||
return CallNextHookEx(hook_handle_copy, nCode, wParam, lParam); | ||
} | ||
} | ||
|
||
void start_lowlevel_mouse_hook() | ||
{ | ||
if (!hook_handle) | ||
{ | ||
hook_handle = SetWindowsHookEx(WH_MOUSE_LL, hook_proc, GetModuleHandle(NULL), NULL); | ||
hook_handle_copy = hook_handle; | ||
if (!hook_handle) | ||
{ | ||
throw std::runtime_error("Cannot install mouse listener"); | ||
} | ||
} | ||
} | ||
|
||
void stop_lowlevel_mouse_hook() | ||
{ | ||
if (hook_handle) | ||
{ | ||
UnhookWindowsHookEx(hook_handle); | ||
hook_handle = nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
#include <interface/lowlevel_mouse_event_data.h> | ||
|
||
void start_lowlevel_mouse_hook(); | ||
void stop_lowlevel_mouse_hook(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters