@@ -5,9 +5,6 @@ use indexmap::IndexMap;
5
5
use ini:: { Ini , ParseOption } ;
6
6
use log:: LevelFilter ;
7
7
use windows:: core:: w;
8
- use windows:: Win32 :: UI :: Input :: KeyboardAndMouse :: {
9
- VIRTUAL_KEY , VK_LCONTROL , VK_LMENU , VK_LWIN , VK_RCONTROL , VK_RMENU , VK_RWIN ,
10
- } ;
11
8
12
9
use crate :: utils:: { get_exe_folder, RegKey } ;
13
10
@@ -189,8 +186,8 @@ impl Config {
189
186
pub struct Hotkey {
190
187
pub id : u32 ,
191
188
pub name : String ,
192
- pub modifier : [ VIRTUAL_KEY ; 2 ] ,
193
- pub code : u16 ,
189
+ pub modifier : [ u32 ; 2 ] ,
190
+ pub code : u32 ,
194
191
}
195
192
196
193
impl Hotkey {
@@ -205,123 +202,69 @@ impl Hotkey {
205
202
} )
206
203
}
207
204
208
- pub fn get_modifier ( & self ) -> u16 {
209
- self . modifier [ 0 ] . 0
205
+ pub fn get_modifier ( & self ) -> u32 {
206
+ self . modifier [ 0 ]
210
207
}
211
208
212
- pub fn parse ( value : & str ) -> Option < ( [ VIRTUAL_KEY ; 2 ] , u16 ) > {
213
- let value = value. to_ascii_lowercase ( ) . replace ( ' ' , "" ) ;
209
+ pub fn parse ( value : & str ) -> Option < ( [ u32 ; 2 ] , u32 ) > {
210
+ let value = value
211
+ . to_ascii_lowercase ( )
212
+ . replace ( ' ' , "" )
213
+ . replace ( "vk_" , "" ) ;
214
214
let keys: Vec < & str > = value. split ( '+' ) . collect ( ) ;
215
215
if keys. len ( ) != 2 {
216
216
return None ;
217
217
}
218
218
let modifier = match keys[ 0 ] {
219
- "win" => [ VK_LWIN , VK_RWIN ] ,
220
- "alt" => [ VK_LMENU , VK_RMENU ] ,
221
- "ctrl" => [ VK_LCONTROL , VK_RCONTROL ] ,
219
+ "win" => [ 0xe05b , 0xe05c ] ,
220
+ "alt" => [ 0x38 , 0xe038 ] ,
221
+ "ctrl" => [ 0x1d , 0xe01d ] ,
222
222
_ => {
223
223
return None ;
224
224
}
225
225
} ;
226
+ // see <https://kbdlayout.info/kbdus/overview+scancodes>
226
227
let code = match keys[ 1 ] {
227
- "backspace" => 0x08 ,
228
- "tab" => 0x09 ,
229
- "clear" => 0x0c ,
230
- "enter" => 0x0d ,
231
- "pause" => 0x13 ,
232
- "capslock" => 0x14 ,
233
- "escape" => 0x1b ,
234
- "space" => 0x20 ,
235
- "pageup" => 0x21 ,
236
- "pagedown" => 0x22 ,
237
- "end" => 0x23 ,
238
- "home" => 0x24 ,
239
- "left" => 0x25 ,
240
- "up" => 0x26 ,
241
- "right" => 0x27 ,
242
- "down" => 0x28 ,
243
- "select" => 0x29 ,
244
- "print" => 0x2a ,
245
- "printscreen" => 0x2c ,
246
- "insert" => 0x2d ,
247
- "delete" => 0x2e ,
248
-
249
- "0" => 0x30 ,
250
- "1" => 0x31 ,
251
- "2" => 0x32 ,
252
- "3" => 0x33 ,
253
- "4" => 0x34 ,
254
- "5" => 0x35 ,
255
- "6" => 0x36 ,
256
- "7" => 0x37 ,
257
- "8" => 0x38 ,
258
- "9" => 0x39 ,
259
- "a" => 0x41 ,
260
- "b" => 0x42 ,
261
- "c" => 0x43 ,
262
- "d" => 0x44 ,
263
- "e" => 0x45 ,
264
- "f" => 0x46 ,
265
- "g" => 0x47 ,
266
- "h" => 0x48 ,
267
- "i" => 0x49 ,
268
- "j" => 0x4a ,
269
- "k" => 0x4b ,
270
- "l" => 0x4c ,
271
- "m" => 0x4d ,
272
- "n" => 0x4e ,
273
- "o" => 0x4f ,
274
- "p" => 0x50 ,
275
- "q" => 0x51 ,
276
- "r" => 0x52 ,
277
- "s" => 0x53 ,
278
- "t" => 0x54 ,
279
- "u" => 0x55 ,
280
- "v" => 0x56 ,
281
- "w" => 0x57 ,
282
- "x" => 0x58 ,
283
- "y" => 0x59 ,
284
- "z" => 0x5a ,
285
-
286
- "f1" => 0x70 ,
287
- "f2" => 0x71 ,
288
- "f3" => 0x72 ,
289
- "f4" => 0x73 ,
290
- "f5" => 0x74 ,
291
- "f6" => 0x75 ,
292
- "f7" => 0x76 ,
293
- "f8" => 0x77 ,
294
- "f9" => 0x78 ,
295
- "f10" => 0x79 ,
296
- "f11" => 0x7a ,
297
- "f12" => 0x7b ,
298
- "numlock" => 0x90 ,
299
- "scrolllock" => 0x91 ,
300
-
301
- ":" | ";" | "vk_oem_1" => 0xba ,
302
- "+" | "=" | "vk_oem_plus" => 0xbb ,
303
- "<" | "," | "vk_oem_comma" => 0xbc ,
304
- "-" | "_" | "vk_oem_minus" => 0xbd ,
305
- ">" | "." | "vk_oem_period" => 0xbe ,
306
- "?" | "/" | "vk_oem_2" => 0xbf ,
307
- "~" | "`" | "vk_oem_3" => 0xc0 ,
308
- "{" | "[" | "vk_oem_4" => 0xdb ,
309
- "|" | "\\ " | "vk_oem_5" => 0xdc ,
310
- "}" | "]" | "vk_oem_6" => 0xdd ,
311
- "\" " | "'" | "vk_oem_7" => 0xde ,
312
- "§" | "!" | "vk_oem_8" => 0xdf ,
313
- "vk_oem_102" => 0xe2 ,
314
- "vk_processkey" => 0xe5 ,
315
- "vk_packet" => 0xe7 ,
316
- "vk_attn" => 0xf6 ,
317
- "vk_crsel" => 0xf7 ,
318
- "vk_exsel" => 0xf8 ,
319
- "vk_ereof" => 0xf9 ,
320
- "vk_play" => 0xfa ,
321
- "vk_zoom" => 0xfb ,
322
- "vk_noname" => 0xfc ,
323
- "vk_pa1" => 0xfd ,
324
- "vk_oem_clear" => 0xfe ,
228
+ "-" | "_" | "oem_minus" => 0x0c ,
229
+ "+" | "=" | "oem_plus" => 0x0d ,
230
+ "bs" | "backspace" => 0x0e ,
231
+ "tab" => 0x0f ,
232
+ "{" | "[" | "oem_4" => 0x1a ,
233
+ "}" | "]" | "oem_6" => 0x1b ,
234
+ ":" | ";" | "oem_1" => 0x27 ,
235
+ "\" " | "'" | "oem_7" => 0x28 ,
236
+ "~" | "`" | "oem_3" => 0x29 ,
237
+ "|" | "\\ " | "oem_5" => 0x2b ,
238
+ "<" | "," | "oem_comma" => 0x33 ,
239
+ ">" | "." | "oem_period" => 0x34 ,
240
+ "?" | "/" | "oem_2" => 0x35 ,
241
+ "capslock" => 0x3a ,
242
+ "f1" => 0x3b ,
243
+ "f2" => 0x3c ,
244
+ "f3" => 0x3d ,
245
+ "f4" => 0x3e ,
246
+ "f5" => 0x3f ,
247
+ "f6" => 0x40 ,
248
+ "f7" => 0x41 ,
249
+ "f8" => 0x42 ,
250
+ "f9" => 0x43 ,
251
+ "f10" => 0x44 ,
252
+ "scrolllock" => 0x46 ,
253
+ "prtsc" | "printscreen" => 0x54 ,
254
+ "oem_102" => 0x56 ,
255
+ "f11" => 0x57 ,
256
+ "f12" => 0x58 ,
257
+ "home" => 0xe047 ,
258
+ "up" => 0xe048 ,
259
+ "pageup" => 0xe049 ,
260
+ "left" => 0xe04b ,
261
+ "right" => 0xe04d ,
262
+ "end" => 0xe04f ,
263
+ "down" => 0xe050 ,
264
+ "pagedown" => 0xe051 ,
265
+ "insert" => 0xe052 ,
266
+ "delete" => 0xe053 ,
267
+ "menu" => 0xe05d ,
325
268
_ => return None ,
326
269
} ;
327
270
Some ( ( modifier, code) )
@@ -381,10 +324,7 @@ mod tests {
381
324
382
325
#[ test]
383
326
fn test_hotkey ( ) {
384
- assert_eq ! ( Hotkey :: parse( "alt + `" ) , Some ( ( [ VK_LMENU , VK_RMENU ] , 0xc0 ) ) ) ;
385
- assert_eq ! (
386
- Hotkey :: parse( "alt + tab" ) ,
387
- Some ( ( [ VK_LMENU , VK_RMENU ] , 0x09 ) )
388
- ) ;
327
+ assert_eq ! ( Hotkey :: parse( "alt + `" ) , Some ( ( [ 0x38 , 0xe038 ] , 0x29 ) ) ) ;
328
+ assert_eq ! ( Hotkey :: parse( "alt + tab" ) , Some ( ( [ 0x38 , 0xe038 ] , 0x0f ) ) ) ;
389
329
}
390
330
}
0 commit comments