Dreamine.UI.Wpf.Equipment 1.0.1
Dreamine.UI.Wpf.Equipment 사용자 인터페이스 기능과 구성 요소를 제공합니다.
로딩중...
검색중...
일치하는것 없음
Key.cs
이 파일의 문서화 페이지로 가기
1using SharpHook.Native;
2using System.Windows;
3using System.Windows.Controls;
4using Dreamine.UI.Abstractions.VirtualKeyboard;
5
7
16public class Key : Button
17{
18 #region Variable
19
28 private static Dictionary<KeyCode, KeyData> _dicKeyData = new();
29
30 #endregion
31
32 #region Dependency Property
33
34 #region IsPressed
35
44 public static readonly new DependencyProperty IsPressedProperty =
45 DependencyProperty.Register(nameof(IsPressed),
46 typeof(bool),
47 typeof(Key));
48
57 public new bool IsPressed
58 {
59 get { return (bool)GetValue(IsPressedProperty); }
60 set { SetValue(IsPressedProperty, value); }
61 }
62
63 #endregion
64
65 #region KeyCode
66
75 public static readonly DependencyProperty KeyCodeProperty =
76 DependencyProperty.Register(nameof(KeyCode), typeof(KeyCode), typeof(Key));
77
87 {
88 get { return (KeyCode)GetValue(KeyCodeProperty); }
89 set { SetValue(KeyCodeProperty, value); }
90 }
91
92 #endregion Public Method
93
134 public void UpdateKey(bool shift, bool capsLock, LanguageCode languageCode, bool imeMode)
135 {
136 if (!_dicKeyData.TryGetValue(KeyCode, out var keyData)) return;
137
138 Content = GetDisplayText(shift, capsLock, languageCode, imeMode);
139 }
140
189 public string GetDisplayText(bool shift, bool capsLock, LanguageCode languageCode, bool imeMode)
190 {
191 if (!_dicKeyData.TryGetValue(KeyCode, out var keyData))
192 return string.Empty;
193
194 var (displayKey, displayShiftKey) = GetKeyData(imeMode ? languageCode : LanguageCode.en_US);
195
196 if (KeyCode >= KeyCode.VcA && KeyCode <= KeyCode.VcZ)
197 {
198 if (shift && !capsLock)
199 {
200 if (!string.IsNullOrEmpty(displayShiftKey))
201 {
202 displayKey = displayShiftKey.ToUpper();
203 }
204 else
205 {
206 displayKey = displayKey.ToUpper();
207 }
208 }
209 else if (!shift && capsLock)
210 {
211 displayKey = displayKey.ToUpper();
212 }
213 else if (shift && capsLock)
214 {
215 if (!string.IsNullOrEmpty(displayShiftKey))
216 {
217 displayKey = displayShiftKey.ToLower();
218 }
219 else
220 {
221 displayKey = displayKey.ToLower();
222 }
223 }
224 }
225 else if (shift && !string.IsNullOrEmpty(keyData.ShiftKey))
226 {
227 displayKey = keyData.ShiftKey;
228 }
229
230 return displayKey;
231 }
232
233 #endregion
234
235 #region Constructor
236
245 static Key()
246 {
247 MappingKeys();
248 }
249
258 public Key()
259 {
260 Focusable = false;
261 IsTabStop = false;
262 ClickMode = ClickMode.Press;
263 }
264
265 #endregion
266
267
268 #region Private Method
301 private (string, string) GetKeyData(LanguageCode language)
302 {
303 var keyData = _dicKeyData[KeyCode];
304
305 var key = language switch
306 {
307 LanguageCode.en_US => keyData.DefaultKey,
308 LanguageCode.ko_KR => keyData.KorKey,
309 LanguageCode.zh_CN => keyData.ChnKey,
310 _ => keyData.DefaultKey
311 };
312
313 var shiftKey = language switch
314 {
315 LanguageCode.en_US => keyData.ShiftKey,
316 LanguageCode.ko_KR => keyData.KorShiftKey,
317 LanguageCode.zh_CN => keyData.ChnShiftKey,
318 _ => keyData.ShiftKey
319 };
320
321 if (string.IsNullOrEmpty(key))
322 {
323 key = keyData.DefaultKey;
324 }
325
326 return (key, shiftKey);
327 }
328
337 private static void MappingKeys()
338 {
339 _dicKeyData = new()
340 {
341 { KeyCode.Vc1, new(defaultKey: "1", shiftKey: "!" ) },
342 { KeyCode.Vc2, new(defaultKey: "2", shiftKey: "@" ) },
343 { KeyCode.Vc3, new(defaultKey: "3", shiftKey: "#" ) },
344 { KeyCode.Vc4, new(defaultKey: "4", shiftKey: "$" ) },
345 { KeyCode.Vc5, new(defaultKey: "5", shiftKey: "%" ) },
346 { KeyCode.Vc6, new(defaultKey: "6", shiftKey: "^" ) },
347 { KeyCode.Vc7, new(defaultKey: "7", shiftKey: "&" ) },
348 { KeyCode.Vc8, new(defaultKey: "8", shiftKey: "*" ) },
349 { KeyCode.Vc9, new(defaultKey: "9", shiftKey: "(" ) },
350 { KeyCode.Vc0, new(defaultKey: "0", shiftKey: ")" ) },
351
352 { KeyCode.VcA, new(defaultKey: "a", korKey: "ㅁ", chnKey: "日") },
353 { KeyCode.VcB, new(defaultKey: "b", korKey: "ㅠ", chnKey: "月") },
354 { KeyCode.VcC, new(defaultKey: "c", korKey: "ㅊ", chnKey: "金") },
355 { KeyCode.VcD, new(defaultKey: "d", korKey: "ㅇ", chnKey: "木") },
356 { KeyCode.VcE, new(defaultKey: "e", korKey: "ㄷ", korShiftKey: "ㄸ", chnKey: "水") },
357 { KeyCode.VcF, new(defaultKey: "f", korKey: "ㄹ", chnKey: "火") },
358 { KeyCode.VcG, new(defaultKey: "g", korKey: "ㅎ", chnKey: "土") },
359 { KeyCode.VcH, new(defaultKey: "h", korKey: "ㅗ", chnKey: "竹") },
360 { KeyCode.VcI, new(defaultKey: "i", korKey: "ㅑ", chnKey: "戈") },
361 { KeyCode.VcJ, new(defaultKey: "j", korKey: "ㅓ", chnKey: "十") },
362 { KeyCode.VcK, new(defaultKey: "k", korKey: "ㅏ", chnKey: "大") },
363 { KeyCode.VcL, new(defaultKey: "l", korKey: "ㅣ", chnKey: "中") },
364 { KeyCode.VcM, new(defaultKey: "m", korKey: "ㅡ", chnKey: "一") },
365 { KeyCode.VcN, new(defaultKey: "n", korKey: "ㅜ", chnKey: "弓") },
366 { KeyCode.VcO, new(defaultKey: "o", korKey: "ㅐ", korShiftKey: "ㅒ", chnKey: "人") },
367 { KeyCode.VcP, new(defaultKey: "p", korKey: "ㅔ", korShiftKey : "ㅖ", chnKey: "心") },
368 { KeyCode.VcQ, new(defaultKey: "q", korKey: "ㅂ", korShiftKey : "ㅃ", chnKey: "手") },
369 { KeyCode.VcR, new(defaultKey: "r", korKey: "ㄱ", korShiftKey : "ㄲ", chnKey: "口") },
370 { KeyCode.VcS, new(defaultKey: "s", korKey: "ㄴ", chnKey: "戶") },
371 { KeyCode.VcT, new(defaultKey: "t", korKey: "ㅅ", korShiftKey: "ㅆ", chnKey: "甘") },
372 { KeyCode.VcU, new(defaultKey: "u", korKey: "ㅕ", chnKey: "山") },
373 { KeyCode.VcV, new(defaultKey: "v", korKey: "ㅍ", chnKey: "女") },
374 { KeyCode.VcW, new(defaultKey: "w", korKey: "ㅈ", korShiftKey: "ㅉ", chnKey: "田") },
375 { KeyCode.VcX, new(defaultKey: "x", korKey: "ㅌ", chnKey: "難") },
376 { KeyCode.VcY, new(defaultKey: "y", korKey: "ㅛ", chnKey: "卜") },
377 { KeyCode.VcZ, new(defaultKey: "z", korKey: "ㅋ", chnKey: "重") },
378
379 { KeyCode.VcBackQuote, new(defaultKey: "`", shiftKey: "~") },
380 { KeyCode.VcMinus, new(defaultKey: "-", shiftKey: "_") },
381 { KeyCode.VcEquals, new(defaultKey: "=", shiftKey: "+") },
382 { KeyCode.VcBackspace, new(defaultKey: "Backspace") },
383 { KeyCode.VcTab, new(defaultKey: "Tab") },
384 { KeyCode.VcOpenBracket, new(defaultKey: "[", shiftKey: "{") },
385 { KeyCode.VcCloseBracket, new(defaultKey: "]", shiftKey: "}") },
386 { KeyCode.VcBackslash, new(defaultKey: "\\", shiftKey: "|") },
387 { KeyCode.VcCapsLock, new(defaultKey: "Caps Lock") },
388 { KeyCode.VcSemicolon, new(defaultKey: ";", shiftKey: ":") },
389 { KeyCode.VcQuote, new(defaultKey: "'", shiftKey: "″") },
390 { KeyCode.VcEnter, new(defaultKey: "Enter") },
391 { KeyCode.VcLeftShift, new(defaultKey: "Shift") },
392 { KeyCode.VcComma, new(defaultKey: ",", shiftKey: "<") },
393 { KeyCode.VcPeriod, new(defaultKey: ".", shiftKey: ">") },
394 { KeyCode.VcSlash, new(defaultKey: "/", shiftKey: "?") },
395 { KeyCode.VcSpace, new(defaultKey: "Space")},
396 { KeyCode.VcRightAlt, new(defaultKey: "Alt")},
397 { KeyCode.VcLeftControl, new(defaultKey: "Ctrl")},
398 { KeyCode.VcEscape, new(defaultKey: "Esc")},
399
400 // NumPad
401 { KeyCode.VcNumPad0, new(defaultKey: "0") },
402 { KeyCode.VcNumPad1, new(defaultKey: "1") },
403 { KeyCode.VcNumPad2, new(defaultKey: "2") },
404 { KeyCode.VcNumPad3, new(defaultKey: "3") },
405 { KeyCode.VcNumPad4, new(defaultKey: "4") },
406 { KeyCode.VcNumPad5, new(defaultKey: "5") },
407 { KeyCode.VcNumPad6, new(defaultKey: "6") },
408 { KeyCode.VcNumPad7, new(defaultKey: "7") },
409 { KeyCode.VcNumPad8, new(defaultKey: "8") },
410 { KeyCode.VcNumPad9, new(defaultKey: "9") },
411
412 // Arrow
413 { KeyCode.VcLeft, new(defaultKey: "◀") },
414 { KeyCode.VcRight, new(defaultKey: "▶") },
415 };
416 }
417
418 #endregion
419}
static Dictionary< KeyCode, KeyData > _dicKeyData
Definition Key.cs:28
static readonly new DependencyProperty IsPressedProperty
Definition Key.cs:44
string GetKeyData(LanguageCode language)
Definition Key.cs:301
string GetDisplayText(bool shift, bool capsLock, LanguageCode languageCode, bool imeMode)
Definition Key.cs:189
static readonly DependencyProperty KeyCodeProperty
Definition Key.cs:75
void UpdateKey(bool shift, bool capsLock, LanguageCode languageCode, bool imeMode)
Definition Key.cs:134