Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added arguments so that a user can change rectangle and delay without recompiling #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "Keine Konfigurationen"
}
7 changes: 7 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"ExpandedNodes": [
""
],
"SelectedNode": "\\README.md",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
Binary file added .vs/tinyhotcorner/v16/.suo
Binary file not shown.
Binary file added .vs/tinyhotcorner/v16/Browse.VC.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This is a **very** minimal hotcorner app, written in C. You can adjust parameter

Zero state is stored anywhere, no registry keys or configuration files.

- If you want to configure something, edit the code and recompile.
- If you want to configure something, use the arguments or edit the code and recompile. ()
- If you want to uninstall it, just delete it.

## Instructions
Expand Down Expand Up @@ -55,7 +55,14 @@ Additionally, it is possible to build hotcorner on Linux using MinGW.

### Configuration

All configuration requires modifying the parameters in `hotcorner.c` and recompiling.
Use the arguments to define the reactangle position and the delay.
Size of the rectangle and delay until its activated can be changed via arguments. The first four arguments define the size and positon of the reactangle,
the fifth argument is the delay in milliseconds.
The order of the arguments is top, left, right, bottom. E.g. if you want a square at the top left, your arguments are -50 -50 50 50, for the bottom left on a 1080 pixel screen, you could use
1070, 20, -20, 1100. To use the arguments make a shortcut to your hotcorner.exe and put the shortcut into "%USERPROFILE%\Start Menu\Programs\Startup\" instead of hotcorner.exe
In the target of the shortcut add the arguments after hotcorner.exe. E.g. "your/path/to/hotcorner.exe -50 -50 50 50 100"
If no arguments are provided, the default is used. (-20 -20 20 20 300)
Further configuration requires modifying the parameters in `hotcorner.c` and recompiling.

* `RECT kHotcorner` - The coordinates of the hot zone.
* `INPUT kCornerInput[]` - Input sent on activation.
Expand All @@ -70,6 +77,7 @@ GPL3

* Tavis Ormandy [@taviso](https://github.com/taviso/) - Original Author
* Ahmed Samy [@asamy](https://github.com/asamy) - HotKey support
* Pascal Jaeger [@Schievel1]https://github.com/Schievel1/ - Command line arguments

## Variations

Expand Down
35 changes: 26 additions & 9 deletions hotcorner.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
// If the mouse enters this rectangle, activate the hot corner function.
// There are some hints about changing corners here
// https://github.com/taviso/hotcorner/issues/7#issuecomment-269367351
static const RECT kHotCorner = {
.top = -20,
.left = -20,
.right = +20,
static RECT kHotCorner = {
.top = -20,
.left = -20,
.right = +20,
.bottom = +20,
};

Expand All @@ -39,7 +39,7 @@ static const INPUT kCornerInput[] = {
};

// How long cursor has to linger in the kHotCorner RECT to trigger input.
static const DWORD kHotDelay = 300;
static DWORD kHotDelay = 300;

// You can exit the application using the hot key CTRL+ALT+C by default, if it
// interferes with some application you're using (e.g. a full screen game).
Expand All @@ -65,8 +65,8 @@ static DWORD WINAPI CornerHotFunc(LPVOID lpParameter)
// Check if any modifier keys are pressed.
if (GetKeyboardState(KeyState)) {
if (KEYDOWN(KeyState[VK_SHIFT]) || KEYDOWN(KeyState[VK_CONTROL])
|| KEYDOWN(KeyState[VK_MENU]) || KEYDOWN(KeyState[VK_LWIN])
|| KEYDOWN(KeyState[VK_RWIN])) {
|| KEYDOWN(KeyState[VK_MENU]) || KEYDOWN(KeyState[VK_LWIN])
|| KEYDOWN(KeyState[VK_RWIN])) {
return 0;
}
}
Expand All @@ -78,7 +78,7 @@ static DWORD WINAPI CornerHotFunc(LPVOID lpParameter)

// Check co-ordinates.
if (PtInRect(&kHotCorner, Point)) {
#pragma warning(suppress : 4090)
#pragma warning(suppress : 4090)
if (SendInput(_countof(kCornerInput), kCornerInput, sizeof(INPUT)) != _countof(kCornerInput)) {
return 1;
}
Expand All @@ -89,7 +89,7 @@ static DWORD WINAPI CornerHotFunc(LPVOID lpParameter)

static LRESULT CALLBACK MouseHookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
MSLLHOOKSTRUCT *evt = (MSLLHOOKSTRUCT *) lParam;
MSLLHOOKSTRUCT* evt = (MSLLHOOKSTRUCT*)lParam;

// If the mouse hasn't moved, we're done.
if (wParam != WM_MOUSEMOVE)
Expand Down Expand Up @@ -136,6 +136,23 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
MSG Msg;
HHOOK MouseHook;

// get arguments from the command line. First four arguments are the coordinates of the rectangle that activates the hot corner
// fifth argument is the delay it takes to activate the hot corner
char* ptr;
char* arg1 = { strtok_s(lpCmdLine, " ", &ptr) };
char* arg2 = { strtok_s(NULL, " ", &ptr) };
char* arg3 = { strtok_s(NULL, " ", &ptr) };
char* arg4 = { strtok_s(NULL, " ", &ptr) };
char* arg5 = { strtok_s(NULL, " ", &ptr) };

if (arg1 && arg1[0] && arg2 && arg2[0] && arg3 && arg3[0] && arg4 && arg4[0]) {
kHotCorner.top = atol(arg1);
kHotCorner.left = atol(arg2);
kHotCorner.right = atol(arg3);
kHotCorner.bottom = atol(arg4);
kHotDelay = atol(arg5);
}

if (!(MouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookCallback, NULL, 0)))
return 1;

Expand Down
Binary file added hotcorner.exe
Binary file not shown.
Binary file added hotcorner.obj
Binary file not shown.
Binary file added version.res
Binary file not shown.