summaryrefslogtreecommitdiff
path: root/plugins/HwHotKeys/src/HwHotKeys_Util.cpp
blob: 4d017cba59e4a198ff50c1ee63975dda3e05eacf (plain)
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
/* ============================================================================
Hardware HotKeys plugin for Miranda NG.
Copyright © Eugene f2065, http://f2065.narod.ru, f2065 mail.ru, ICQ 35078112
 
This program is free software; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111 - 1307, USA.
============================================================================ */

#include "stdafx.h"



// сравнивает текущий нажатый сканкод с указанным
BOOL HwHotKeys_CompareCurrentScancode(DWORD scancode)
{
	if (key_code == scancode) // key_code - текущий нажатый на клавиатуре сканкод.
	{
		return true; // сканкод напрямую совпал - TRUE.
	}
	if (!(scancode & 0x00F00000)) // проверяем нет ли в сканкоде запроса на любой из левого/правого регистра.
	{
		return false;
	}
	DWORD tmp1, tmp2; // битовые маски: 0xF0000000 - левые кнопки Sft/Ctr/Alt/Win, 0x0F000000 - правые кнопки, 0x00F00000 - любые кнопки Sft/Ctr/Alt/Win
	tmp1 = key_code >> 8;    // сдвигаем биты левых и правых кнопок.
	tmp2 = key_code >> 4;
	tmp1 |= tmp2;
	tmp1 &= 0x00F00000;
	tmp2 = (key_code | tmp1) & 0x00FFFFFF;
	if (tmp2 == scancode)
	{
		return true;
	}
	return false;
}



// печатает в буфер key_name_buffer текстовое описание нажатой комбинации кнопок
// Кодировка ANSI (для экономии места, всё равно названия клавиш английские)
VOID HwHotKeys_PrintFullKeyname(DWORD scancode)
{
	key_name_buffer[0] = 0;
	if (!scancode) // если нулевой сканкод - то пустую строку делаем.
	{
		return;
	}

	if (scancode & key_flag_sl) // L_Shift
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_SL);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_sr) // R_Shift
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_SR);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_ss) // Shift
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_SS);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}

	if (scancode & key_flag_cl) // L_Ctrl
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_CL);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_cr) // R_Ctrl
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_CR);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_cc) // Ctrl
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_CC);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}

	if (scancode & key_flag_al) // L_Alt
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_AL);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_ar) // R_Alt
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_AR);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_aa) // Alt
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_AA);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}

	if (scancode & key_flag_wl) // L_Win
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_WL);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_wr) // R_Win
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_WR);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}
	if (scancode & key_flag_ww) // Win
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), t_WW);
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), " + ");
	}

	if ((scancode & 0x1FF) < sizeof(key_tab)) // защита от ошибочных данных - чтобы не выйти из таблицы имён.
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), key_tab[(scancode & 0x1FF)]);
	}
	else
	{
		StringCbCatA(key_name_buffer, sizeof(key_name_buffer), "out of range");
	}

	INT_PTR tmp1 = mir_strlen(key_name_buffer); // допечатываем в конеце строки сканкод - для удобства работы с пока ещё не известными (безимянными) кнопками
	StringCbPrintfA(key_name_buffer + tmp1, sizeof(key_name_buffer) - tmp1, " (%03X)", (scancode & 0x1FF));

	return;
}