Win10 HotCorner热角小程序

想念Linux下compiz的热角,基于 taviso/hotcorner 改写了一个超级小的hotcorner应用,体积只有37k,占用也足够低:

运行后,鼠标点击屏幕左上角即可切换任务视图。Ctrl+Alt+C退出。要开机启动放到如下文件夹即可:

"%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"

点此下载 ,有用下方点个赞。

由于用的是鼠标点击事件,所以逻辑和代码很简单:

#define WIN32_LEAN_AND_MEAN
#include 
#include 

#pragma comment(lib, "USER32")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")

#define KEYDOWN(k) ((k) & 0x80)

// based on https://github.com/taviso/hotcorner
// It just works. dylanchu 2020-02-07

static const RECT kHotCorner = {
    .top    = 0,
    .left   = 0,
    .right  = +1,
    .bottom = +1,
};

// Input to inject when corner activated (Win+Tab by default).
static const INPUT kCornerInput[] = {
    { INPUT_KEYBOARD, .ki = { VK_LWIN, .dwFlags = 0 }},
    { INPUT_KEYBOARD, .ki = { VK_TAB,  .dwFlags = 0 }},
    { INPUT_KEYBOARD, .ki = { VK_TAB,  .dwFlags = KEYEVENTF_KEYUP }},
    { INPUT_KEYBOARD, .ki = { VK_LWIN, .dwFlags = KEYEVENTF_KEYUP }},
};

// 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).
static const DWORD kHotKeyModifiers = MOD_CONTROL | MOD_ALT;
static const DWORD kHotKey = 'C';

static HANDLE CornerThread = INVALID_HANDLE_VALUE;

static DWORD WINAPI CornerHotFunc(LPVOID lpParameter)
{
    BYTE KeyState[256];
    POINT Point;

    // 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])) {
            return 0;
        }
    }

    #pragma warning(suppress : 4090)
    if (SendInput(_countof(kCornerInput), kCornerInput, sizeof(INPUT)) != _countof(kCornerInput)) {
        return 1;
    }

    return 0;
}

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

    // If the mouse hasn't been clicked, we're done.

    if (wParam == WM_LBUTTONDOWN && PtInRect(&kHotCorner, evt->pt)) {
        CornerThread = CreateThread(NULL, 0, CornerHotFunc, NULL, 0, NULL);
        return 1;  // 消息不再继续传递
    } else if (wParam == WM_LBUTTONUP && CornerThread != INVALID_HANDLE_VALUE) {
        CornerThread = INVALID_HANDLE_VALUE;
        return 1;
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MSG Msg;
    HHOOK MouseHook;

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

    RegisterHotKey(NULL, 1, kHotKeyModifiers, kHotKey);

    while (GetMessage(&Msg, NULL, 0, 0)) {
        if (Msg.message == WM_HOTKEY) {
            break;
        }
        DispatchMessage(&Msg);
    }

    UnhookWindowsHookEx(MouseHook);

    return Msg.wParam;
}

Win10 HotCorner热角小程序_第1张图片



禁用Windows Defender,Cortana中输入命令提示符,以管理员身份运行:

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v "DisableAntiSpyware" /d 1 /t REG_DWORD /f

回车后重启。

如果需要启用Windows Defender,Cortana中输入命令提示符,以管理员身份运行:

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /v "DisableAntiSpyware" /d 0 /t REG_DWORD /f

回车后重启。

https://answers.microsoft.com/zh-hans/windows/forum/all/%E5%A6%82%E4%BD%95%E5%BD%BB%E5%BA%95%E5%85%B3/5a574a96-0f92-4b95-97ac-10df8975b82d

你可能感兴趣的:(Win10 HotCorner热角小程序)