📄 hotkey.c
字号:
/*********************************************************************
Name:
HotKey.c
Module:
WSENGINE
Version:
1.00
Description:
Windows Hot Key Manager
Date:
1993 Oct. - 1993 Dec.
Created By:
Wang Zhidong
Functions:
DispatchHotKey
Exports:
WseFindHotKey
WseEnumHotKeys
WseRegisterHotKey
WseUnregisterHotKey
WseEnableHotKey
*********************************************************************/
#include <Windows.h>
#include <mate.h>
#include "engine.h"
HOTKEYSTRUCT HotKeys[MAXHOTKEY];
int HotKeyCount = 0;
int FindHotKey (lpName, key)
LPSTR lpName;
WORD key;
{
int i;
ATOM aName;
if (lpName)
aName = GlobalFindAtom (lpName);
else
aName = NULL;
for (i = 0; i < HotKeyCount; i++)
{
if ((aName || key) && (!aName || HotKeys[i].name == aName) &&
(!key || HotKeys[i].key == key))
return i;
}
return -1;
}
HOTKEYSTRUCT FAR * WINAPI WseFindHotKey (LPSTR lpName, UINT key)
{
int i = FindHotKey (lpName, key);
return (i == -1) ? NULL : HotKeys+i;
}
int WINAPI WseEnumHotKeys (ENUMHOTKEYPROC fpProc, LPARAM lParam)
{
int i, j = 0;
for (i = 0; !j && i < HotKeyCount; i++)
j = fpProc (HotKeys+i, lParam);
return j;
}
BOOL WINAPI WseRegisterHotKey (lpName, key, cmd, wParam, lParam, Tag)
LPSTR lpName;
WORD key;
DWORD cmd;
WPARAM wParam;
LPARAM lParam;
BOOL Tag;
{
LPSTR lpStr;
WseUnregisterHotKey (lpName, NULL);
if (HotKeyCount < MAXHOTKEY && key && HIWORD(cmd))
{
if ((Tag & HKT_STRING) && lParam)
{
lpStr = (NPSTR)LocalAlloc (LPTR, lstrlen((LPSTR)lParam)+2);
lstrcpy (lpStr, (LPSTR)lParam);
for (lParam = (LPARAM)lpStr;
*lpStr;
lpStr = AnsiNext (lpStr))
{
if (*lpStr == ';')
*lpStr = 0;
}
}
HotKeys[HotKeyCount].name = GlobalAddAtom (lpName);
HotKeys[HotKeyCount].key = key;
HotKeys[HotKeyCount].sys = HIWORD(cmd);
HotKeys[HotKeyCount].cmd = LOWORD(cmd);
HotKeys[HotKeyCount].wParam = wParam;
HotKeys[HotKeyCount].lParam = lParam;
HotKeys[HotKeyCount].Tag = Tag;
HotKeyCount ++;
return TRUE;
}
else
return FALSE;
}
BOOL WINAPI WseUnregisterHotKey (lpName, key)
LPSTR lpName;
WORD key;
{
int i;
i = FindHotKey (lpName, key);
if (i != -1)
{
if (HotKeys[i].Tag & HKT_STRING)
LocalFree ((HANDLE)LOWORD(HotKeys[i].lParam));
HotKeyCount--;
WseRepMovsb ((LPSTR)(HotKeys+i),
(LPSTR)(HotKeys+i+1),
(HotKeyCount-i) * sizeof(HOTKEYSTRUCT));
return TRUE;
}
return FALSE;
}
BOOL WINAPI WseEnableHotKey (lpName, key, bEnable)
LPSTR lpName;
WORD key;
BOOL bEnable;
{
int i;
i = FindHotKey (lpName, key);
if (i != -1)
{
if (bEnable)
HotKeys[i].Tag &= ~HKT_DISABLE;
else
HotKeys[i].Tag |= HKT_DISABLE;
return TRUE;
}
return FALSE;
}
BOOL FAR DispatchHotKey (wVirtKey, lParam, lpKeyState)
WORD wVirtKey;
LPARAM lParam;
LPBYTE lpKeyState;
{
int i;
static WORD wPrevKey = NULL;
WORD wpk = wPrevKey;
wVirtKey &= 0xff;
wPrevKey = wVirtKey;
if (lpKeyState[VK_CONTROL] & 0x80) wVirtKey |= (VKMASK_CONTROL << 8);
if (lpKeyState[VK_SHIFT] & 0x80) wVirtKey |= (VKMASK_SHIFT << 8);
if (lpKeyState[VK_MENU] & 0x80) wVirtKey |= (VKMASK_MENU << 8);
if (lpKeyState[VK_LBUTTON] & 0x80) wVirtKey |= (VKMASK_LBUTTON << 8);
if (lpKeyState[VK_RBUTTON] & 0x80) wVirtKey |= (VKMASK_RBUTTON << 8);
for (i = 0; i < HotKeyCount; i++)
{
if (HotKeys[i].key == wVirtKey)
{
if (HotKeys[i].Tag & HKT_DISABLE)
return FALSE;
if (wPrevKey == VK_CONTROL || wPrevKey == VK_SHIFT || wPrevKey == VK_MENU)
{
if (wpk != wPrevKey || !(lParam & 0x80000000))
return FALSE;
WseSendControlMessage (HotKeys[i].sys, HotKeys[i].cmd,
HotKeys[i].wParam, HotKeys[i].lParam);
return FALSE;
}
else if (lParam & 0x80000000)
return TRUE;
return WseSendControlMessage (HotKeys[i].sys, HotKeys[i].cmd,
HotKeys[i].wParam, HotKeys[i].lParam);
}
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -