-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Accels.cpp
186 lines (162 loc) · 3.79 KB
/
Accels.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "stdafx.h"
#include "Accels.h"
#include "HotKeys.h"
#include "Options.h"
CAccels::CAccels()
{
m_handleRepeatKeys = false;
m_firstMapTick = 0;
m_activeFirstKey = 0;
m_checkModifierKeys = true;
}
void CAccels::AddAccel(CAccel a)
{
m_multiMap.insert(pair<DWORD, CAccel>(a.Key, a));
}
void CAccels::AddAccel(DWORD cmd, DWORD key, DWORD key2, CString refData)
{
if ((int)key2 <= 0)
{
key2 = 0;
}
CAccel a(key, cmd, key2, refData);
m_multiMap.insert(pair<DWORD, CAccel>(key, a));
}
void CAccels::RemoveAll()
{
m_multiMap.clear();
}
CString CAccels::GetCmdKeyText(DWORD cmd, CString refData)
{
CString cmdShortcutText;
for (multimap<DWORD, CAccel>::iterator it = m_multiMap.begin(); it != m_multiMap.end(); ++it)
{
if (it->second.Cmd == cmd &&
(refData == _T("") || it->second.RefData == refData))
{
if (it->second.Key != 0)
{
cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(it->second.Key);
if (it->second.Key2 != 0)
{
CString cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(it->second.Key2);
if (cmdShortcutText2.GetLength() > 0)
{
cmdShortcutText += _T(" - ");
cmdShortcutText += cmdShortcutText2;
}
}
}
break;
}
}
return cmdShortcutText;
}
bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
{
if((pMsg->message != WM_KEYDOWN && pMsg->message != WM_SYSKEYDOWN))
{
return NULL;
}
// bit 30 (0x40000000) is 1 if this is NOT the first msg of the key
// i.e. auto-repeat may cause multiple msgs of the same key
if((pMsg->lParam &0x40000000) && m_handleRepeatKeys == false)
{
return NULL;
}
m_handleRepeatKeys = false;
if(!pMsg)
{
return NULL;
}
const BYTE vkey = LOBYTE(pMsg->wParam);
BYTE mod = 0;
if (m_checkModifierKeys)
{
mod = GetKeyStateModifiers();
}
const DWORD key = ACCEL_MAKEKEY(vkey, mod);
//CString cs;
//cs.Format(_T("Key: %d, Mod: %d, vkey: %d, diff: %d\r\n"), key, mod, vkey, (GetTickCount() - m_firstMapTick));
//OutputDebugString(cs);
if (m_firstMapTick != 0 &&
(GetTickCount64() - m_firstMapTick) < CGetSetOptions::m_doubleKeyStrokeTimeout)
{
pair<multimap<DWORD, CAccel>::iterator, multimap<DWORD, CAccel>::iterator> ppp;
ppp = m_multiMap.equal_range(m_activeFirstKey);
for (multimap<DWORD, CAccel>::iterator it2 = ppp.first; it2 != ppp.second; ++it2)
{
if (key == it2->second.Key2)
{
a = (*it2).second;
m_firstMapTick = 0;
m_activeFirstKey = 0;
return true;
}
}
}
else
{
m_firstMapTick = 0;
m_activeFirstKey = 0;
pair<multimap<DWORD, CAccel>::iterator, multimap<DWORD, CAccel>::iterator> ppp;
ppp = m_multiMap.equal_range(key);
for (multimap<DWORD, CAccel>::iterator it2 = ppp.first; it2 != ppp.second; ++it2)
{
if (it2->second.Key2 == 0)
{
a = (*it2).second;
//return now as a another command could have a second key defined
//if they don't press the second key this will be handled by a timer on the outside
}
else
{
m_activeFirstKey = key;
m_firstMapTick = GetTickCount64();
break;
}
}
if (a.Cmd > 0 && m_activeFirstKey == 0)
{
return true;
}
}
return false;
}
bool CAccels::ContainsKey(int vKey)
{
CString cmdShortcutText;
for (auto it = m_multiMap.begin(); it != m_multiMap.end(); ++it)
{
if (LOBYTE(it->second.Key) == vKey || LOBYTE(it->second.Key2) == vKey)
{
return true;
}
}
return false;
}
BYTE CAccels::GetKeyStateModifiers()
{
BYTE m = 0;
if(GetKeyState(VK_SHIFT) &0x8000)
{
m |= HOTKEYF_SHIFT;
}
if(GetKeyState(VK_CONTROL) &0x8000)
{
m |= HOTKEYF_CONTROL;
}
if(GetKeyState(VK_MENU) &0x8000)
{
m |= HOTKEYF_ALT;
}
if(GetKeyState(VK_LWIN) &0x8000)
{
m |= HOTKEYF_EXT;
}
if(GetKeyState(VK_RWIN) &0x8000)
{
m |= HOTKEYF_EXT;
}
return m;
}