TouchScreenKeyboard.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. namespace Muchinfo.WPF.Controls.Keyboard
  7. {
  8. /// <summary>
  9. /// Class TouchScreenKeyboard
  10. /// </summary>
  11. public class TouchScreenKeyboard : Window
  12. {
  13. #region Fields
  14. public static readonly DependencyProperty TouchScreenKeyboardProperty =
  15. DependencyProperty.RegisterAttached("TouchScreenKeyboard", typeof(bool), typeof(TouchScreenKeyboard), new UIPropertyMetadata(default(bool), TouchScreenKeyboardPropertyChanged));
  16. /// <summary>
  17. /// The CMD0
  18. /// </summary>
  19. public static RoutedUICommand Cmd0 = new RoutedUICommand();
  20. public static RoutedUICommand Cmd1 = new RoutedUICommand();
  21. public static RoutedUICommand Cmd2 = new RoutedUICommand();
  22. public static RoutedUICommand Cmd3 = new RoutedUICommand();
  23. public static RoutedUICommand Cmd4 = new RoutedUICommand();
  24. public static RoutedUICommand Cmd5 = new RoutedUICommand();
  25. public static RoutedUICommand Cmd6 = new RoutedUICommand();
  26. public static RoutedUICommand Cmd7 = new RoutedUICommand();
  27. public static RoutedUICommand Cmd8 = new RoutedUICommand();
  28. public static RoutedUICommand Cmd9 = new RoutedUICommand();
  29. public static RoutedUICommand CmdA = new RoutedUICommand();
  30. public static RoutedUICommand CmdB = new RoutedUICommand();
  31. public static RoutedUICommand CmdBackspace = new RoutedUICommand();
  32. public static RoutedUICommand CmdC = new RoutedUICommand();
  33. public static RoutedUICommand CmdCapsLock = new RoutedUICommand();
  34. public static RoutedUICommand CmdClear = new RoutedUICommand();
  35. public static RoutedUICommand CmdColon = new RoutedUICommand();
  36. public static RoutedUICommand CmdD = new RoutedUICommand();
  37. public static RoutedUICommand CmdDoubleInvertedComma = new RoutedUICommand();
  38. public static RoutedUICommand CmdE = new RoutedUICommand();
  39. public static RoutedUICommand CmdEndCrultBrace = new RoutedUICommand();
  40. public static RoutedUICommand CmdEnter = new RoutedUICommand();
  41. public static RoutedUICommand CmdF = new RoutedUICommand();
  42. public static RoutedUICommand CmdG = new RoutedUICommand();
  43. public static RoutedUICommand CmdGreaterThan = new RoutedUICommand();
  44. public static RoutedUICommand CmdH = new RoutedUICommand();
  45. public static RoutedUICommand CmdI = new RoutedUICommand();
  46. public static RoutedUICommand CmdJ = new RoutedUICommand();
  47. public static RoutedUICommand CmdK = new RoutedUICommand();
  48. public static RoutedUICommand CmdL = new RoutedUICommand();
  49. public static RoutedUICommand CmdLessThan = new RoutedUICommand();
  50. public static RoutedUICommand CmdM = new RoutedUICommand();
  51. public static RoutedUICommand CmdMinus = new RoutedUICommand();
  52. public static RoutedUICommand CmdN = new RoutedUICommand();
  53. public static RoutedUICommand CmdO = new RoutedUICommand();
  54. public static RoutedUICommand CmdOpenCrulyBrace = new RoutedUICommand();
  55. public static RoutedUICommand CmdOR = new RoutedUICommand();
  56. public static RoutedUICommand CmdP = new RoutedUICommand();
  57. public static RoutedUICommand CmdPlus = new RoutedUICommand();
  58. public static RoutedUICommand CmdQ = new RoutedUICommand();
  59. public static RoutedUICommand CmdQuestion = new RoutedUICommand();
  60. public static RoutedUICommand CmdR = new RoutedUICommand();
  61. public static RoutedUICommand CmdS = new RoutedUICommand();
  62. public static RoutedUICommand CmdShift = new RoutedUICommand();
  63. public static RoutedUICommand CmdSpaceBar = new RoutedUICommand();
  64. public static RoutedUICommand CmdT = new RoutedUICommand();
  65. public static RoutedUICommand CmdTab = new RoutedUICommand();
  66. public static RoutedUICommand CmdTlide = new RoutedUICommand();
  67. public static RoutedUICommand CmdU = new RoutedUICommand();
  68. public static RoutedUICommand CmdV = new RoutedUICommand();
  69. public static RoutedUICommand Cmdw = new RoutedUICommand();
  70. public static RoutedUICommand CmdX = new RoutedUICommand();
  71. public static RoutedUICommand CmdY = new RoutedUICommand();
  72. public static RoutedUICommand CmdZ = new RoutedUICommand();
  73. private static bool _capsLockFlag;
  74. private static Control _currentControl;
  75. private const double HeightTouchKeyboard = 211d;
  76. private static Window _instanceObject;
  77. private static Brush _previousTextBoxBackgroundBrush = null;
  78. private static Brush _previousTextBoxBorderBrush = null;
  79. private static Thickness _previousTextBoxBorderThickness;
  80. private static bool _shiftFlag;
  81. private static double _widthTouchKeyboard = 540;
  82. #endregion Fields
  83. #region Constructors
  84. /// <summary>
  85. /// Initializes static members of the <see cref="TouchScreenKeyboard"/> class.
  86. /// </summary>
  87. static TouchScreenKeyboard()
  88. {
  89. DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchScreenKeyboard), new FrameworkPropertyMetadata(typeof(TouchScreenKeyboard)));
  90. SetCommandBinding();
  91. }
  92. /// <summary>
  93. /// Initializes a new instance of the <see cref="TouchScreenKeyboard"/> class.
  94. /// </summary>
  95. public TouchScreenKeyboard()
  96. {
  97. this.Width = WidthTouchKeyboard;
  98. this.Height = HeightTouchKeyboard;
  99. }
  100. #endregion Constructors
  101. #region Properties
  102. public static string TouchScreenText
  103. {
  104. get
  105. {
  106. if (_currentControl is TextBox)
  107. {
  108. return ((TextBox)_currentControl).Text;
  109. }
  110. else if (_currentControl is PasswordBox)
  111. {
  112. return ((PasswordBox)_currentControl).Password;
  113. }
  114. else return "";
  115. }
  116. set
  117. {
  118. if (_currentControl is TextBox)
  119. {
  120. ((TextBox)_currentControl).Text = value;
  121. }
  122. else if (_currentControl is PasswordBox)
  123. {
  124. ((PasswordBox)_currentControl).Password = value;
  125. }
  126. }
  127. }
  128. public static double WidthTouchKeyboard
  129. {
  130. get { return _widthTouchKeyboard; }
  131. set { _widthTouchKeyboard = value; }
  132. }
  133. protected static bool CapsLockFlag
  134. {
  135. get { return TouchScreenKeyboard._capsLockFlag; }
  136. set { TouchScreenKeyboard._capsLockFlag = value; }
  137. }
  138. protected static bool ShiftFlag
  139. {
  140. get { return _shiftFlag; }
  141. set { _shiftFlag = value; }
  142. }
  143. #endregion Properties
  144. #region Methods
  145. public static void Dispose()
  146. {
  147. _currentControl = null;
  148. _previousTextBoxBackgroundBrush = null;
  149. _previousTextBoxBorderBrush = null;
  150. if (_instanceObject != null)
  151. {
  152. _instanceObject.Close();
  153. _instanceObject = null;
  154. }
  155. }
  156. public static bool GetTouchScreenKeyboard(DependencyObject obj)
  157. {
  158. return (bool)obj.GetValue(TouchScreenKeyboardProperty);
  159. }
  160. public static void SetTouchScreenKeyboard(DependencyObject obj, bool value)
  161. {
  162. obj.SetValue(TouchScreenKeyboardProperty, value);
  163. }
  164. private static void AddKeyBoardINput(char input)
  165. {
  166. if (CapsLockFlag)
  167. {
  168. if (ShiftFlag)
  169. {
  170. TouchScreenKeyboard.TouchScreenText += char.ToLower(input).ToString();
  171. ShiftFlag = false;
  172. }
  173. else
  174. {
  175. TouchScreenKeyboard.TouchScreenText += char.ToUpper(input).ToString();
  176. }
  177. }
  178. else
  179. {
  180. if (!ShiftFlag)
  181. {
  182. TouchScreenKeyboard.TouchScreenText += char.ToLower(input).ToString();
  183. }
  184. else
  185. {
  186. TouchScreenKeyboard.TouchScreenText += char.ToUpper(input).ToString();
  187. ShiftFlag = false;
  188. }
  189. }
  190. }
  191. static void OnGotFocus(object sender, RoutedEventArgs e)
  192. {
  193. Control host = sender as Control;
  194. _previousTextBoxBackgroundBrush = host.Background;
  195. _previousTextBoxBorderBrush = host.BorderBrush;
  196. _previousTextBoxBorderThickness = host.BorderThickness;
  197. host.Background = Brushes.Yellow;
  198. host.BorderBrush = Brushes.Red;
  199. host.BorderThickness = new Thickness(4);
  200. _currentControl = host;
  201. if (_instanceObject == null)
  202. {
  203. FrameworkElement ct = host;
  204. while (true)
  205. {
  206. if (ct is Window)
  207. {
  208. ((Window)ct).Activated += new EventHandler(TouchScreenKeyboard_Activated);
  209. ((Window)ct).Deactivated += new EventHandler(TouchScreenKeyboard_Deactivated);
  210. break;
  211. }
  212. ct = (FrameworkElement)ct.Parent;
  213. }
  214. _instanceObject = new TouchScreenKeyboard();
  215. _instanceObject.AllowsTransparency = true;
  216. _instanceObject.WindowStyle = WindowStyle.None;
  217. _instanceObject.ShowInTaskbar = false;
  218. _instanceObject.ShowInTaskbar = false;
  219. _instanceObject.Topmost = true;
  220. SyncChild();
  221. // host.LayoutUpdated += new EventHandler(tb_LayoutUpdated);
  222. }
  223. }
  224. static void OnLostFocus(object sender, RoutedEventArgs e)
  225. {
  226. Control host = sender as Control;
  227. host.Background = _previousTextBoxBackgroundBrush;
  228. host.BorderBrush = _previousTextBoxBorderBrush;
  229. host.BorderThickness = _previousTextBoxBorderThickness;
  230. if (_instanceObject != null)
  231. {
  232. _instanceObject.Close();
  233. _instanceObject = null;
  234. }
  235. SetTouchScreenKeyboard(host, false);
  236. //设置只有使用按键时才打开键盘。
  237. host.GotFocus -= OnGotFocus;
  238. host.LostFocus -= OnLostFocus;
  239. }
  240. private static void OnUnloaded(object sender, RoutedEventArgs e)
  241. {
  242. if (_instanceObject != null)
  243. {
  244. _instanceObject.Close();
  245. }
  246. }
  247. static void RunCommand(object sender, ExecutedRoutedEventArgs e)
  248. {
  249. if (e.Command == CmdTlide) //First Row
  250. {
  251. if (!ShiftFlag)
  252. {
  253. TouchScreenKeyboard.TouchScreenText += "`";
  254. }
  255. else
  256. {
  257. TouchScreenKeyboard.TouchScreenText += "~";
  258. ShiftFlag = false;
  259. }
  260. }
  261. else if (e.Command == Cmd1)
  262. {
  263. if (!ShiftFlag)
  264. {
  265. TouchScreenKeyboard.TouchScreenText += "1";
  266. }
  267. else
  268. {
  269. TouchScreenKeyboard.TouchScreenText += "!";
  270. ShiftFlag = false;
  271. }
  272. }
  273. else if (e.Command == Cmd2)
  274. {
  275. if (!ShiftFlag)
  276. {
  277. TouchScreenKeyboard.TouchScreenText += "2";
  278. }
  279. else
  280. {
  281. TouchScreenKeyboard.TouchScreenText += "@";
  282. ShiftFlag = false;
  283. }
  284. }
  285. else if (e.Command == Cmd3)
  286. {
  287. if (!ShiftFlag)
  288. {
  289. TouchScreenKeyboard.TouchScreenText += "3";
  290. }
  291. else
  292. {
  293. TouchScreenKeyboard.TouchScreenText += "#";
  294. ShiftFlag = false;
  295. }
  296. }
  297. else if (e.Command == Cmd4)
  298. {
  299. if (!ShiftFlag)
  300. {
  301. TouchScreenKeyboard.TouchScreenText += "4";
  302. }
  303. else
  304. {
  305. TouchScreenKeyboard.TouchScreenText += "$";
  306. ShiftFlag = false;
  307. }
  308. }
  309. else if (e.Command == Cmd5)
  310. {
  311. if (!ShiftFlag)
  312. {
  313. TouchScreenKeyboard.TouchScreenText += "5";
  314. }
  315. else
  316. {
  317. TouchScreenKeyboard.TouchScreenText += "%";
  318. ShiftFlag = false;
  319. }
  320. }
  321. else if (e.Command == Cmd6)
  322. {
  323. if (!ShiftFlag)
  324. {
  325. TouchScreenKeyboard.TouchScreenText += "6";
  326. }
  327. else
  328. {
  329. TouchScreenKeyboard.TouchScreenText += "^";
  330. ShiftFlag = false;
  331. }
  332. }
  333. else if (e.Command == Cmd7)
  334. {
  335. if (!ShiftFlag)
  336. {
  337. TouchScreenKeyboard.TouchScreenText += "7";
  338. }
  339. else
  340. {
  341. TouchScreenKeyboard.TouchScreenText += "&";
  342. ShiftFlag = false;
  343. }
  344. }
  345. else if (e.Command == Cmd8)
  346. {
  347. if (!ShiftFlag)
  348. {
  349. TouchScreenKeyboard.TouchScreenText += "8";
  350. }
  351. else
  352. {
  353. TouchScreenKeyboard.TouchScreenText += "*";
  354. ShiftFlag = false;
  355. }
  356. }
  357. else if (e.Command == Cmd9)
  358. {
  359. if (!ShiftFlag)
  360. {
  361. TouchScreenKeyboard.TouchScreenText += "9";
  362. }
  363. else
  364. {
  365. TouchScreenKeyboard.TouchScreenText += "(";
  366. ShiftFlag = false;
  367. }
  368. }
  369. else if (e.Command == Cmd0)
  370. {
  371. if (!ShiftFlag)
  372. {
  373. TouchScreenKeyboard.TouchScreenText += "0";
  374. }
  375. else
  376. {
  377. TouchScreenKeyboard.TouchScreenText += ")";
  378. ShiftFlag = false;
  379. }
  380. }
  381. else if (e.Command == CmdMinus)
  382. {
  383. if (!ShiftFlag)
  384. {
  385. TouchScreenKeyboard.TouchScreenText += "-";
  386. }
  387. else
  388. {
  389. TouchScreenKeyboard.TouchScreenText += "_";
  390. ShiftFlag = false;
  391. }
  392. }
  393. else if (e.Command == CmdPlus)
  394. {
  395. if (!ShiftFlag)
  396. {
  397. TouchScreenKeyboard.TouchScreenText += "=";
  398. }
  399. else
  400. {
  401. TouchScreenKeyboard.TouchScreenText += "+";
  402. ShiftFlag = false;
  403. }
  404. }
  405. else if (e.Command == CmdBackspace)
  406. {
  407. if (!string.IsNullOrEmpty(TouchScreenKeyboard.TouchScreenText))
  408. {
  409. TouchScreenKeyboard.TouchScreenText = TouchScreenKeyboard.TouchScreenText.Substring(0, TouchScreenKeyboard.TouchScreenText.Length - 1);
  410. }
  411. }
  412. else if (e.Command == CmdTab) //Second Row
  413. {
  414. TouchScreenKeyboard.TouchScreenText += " ";
  415. }
  416. else if (e.Command == CmdQ)
  417. {
  418. AddKeyBoardINput('Q');
  419. }
  420. else if (e.Command == Cmdw)
  421. {
  422. AddKeyBoardINput('w');
  423. }
  424. else if (e.Command == CmdE)
  425. {
  426. AddKeyBoardINput('E');
  427. }
  428. else if (e.Command == CmdR)
  429. {
  430. AddKeyBoardINput('R');
  431. }
  432. else if (e.Command == CmdT)
  433. {
  434. AddKeyBoardINput('T');
  435. }
  436. else if (e.Command == CmdY)
  437. {
  438. AddKeyBoardINput('Y');
  439. }
  440. else if (e.Command == CmdU)
  441. {
  442. AddKeyBoardINput('U');
  443. }
  444. else if (e.Command == CmdI)
  445. {
  446. AddKeyBoardINput('I');
  447. }
  448. else if (e.Command == CmdO)
  449. {
  450. AddKeyBoardINput('O');
  451. }
  452. else if (e.Command == CmdP)
  453. {
  454. AddKeyBoardINput('P');
  455. }
  456. else if (e.Command == CmdOpenCrulyBrace)
  457. {
  458. if (!ShiftFlag)
  459. {
  460. TouchScreenKeyboard.TouchScreenText += "[";
  461. }
  462. else
  463. {
  464. TouchScreenKeyboard.TouchScreenText += "{";
  465. ShiftFlag = false;
  466. }
  467. }
  468. else if (e.Command == CmdEndCrultBrace)
  469. {
  470. if (!ShiftFlag)
  471. {
  472. TouchScreenKeyboard.TouchScreenText += "]";
  473. }
  474. else
  475. {
  476. TouchScreenKeyboard.TouchScreenText += "}";
  477. ShiftFlag = false;
  478. }
  479. }
  480. else if (e.Command == CmdOR)
  481. {
  482. if (!ShiftFlag)
  483. {
  484. TouchScreenKeyboard.TouchScreenText += @"\";
  485. }
  486. else
  487. {
  488. TouchScreenKeyboard.TouchScreenText += "|";
  489. ShiftFlag = false;
  490. }
  491. }
  492. else if (e.Command == CmdCapsLock) ///Third ROw
  493. {
  494. if (!CapsLockFlag)
  495. {
  496. CapsLockFlag = true;
  497. }
  498. else
  499. {
  500. CapsLockFlag = false;
  501. }
  502. }
  503. else if (e.Command == CmdA)
  504. {
  505. AddKeyBoardINput('A');
  506. }
  507. else if (e.Command == CmdS)
  508. {
  509. AddKeyBoardINput('S');
  510. }
  511. else if (e.Command == CmdD)
  512. {
  513. AddKeyBoardINput('D');
  514. }
  515. else if (e.Command == CmdF)
  516. {
  517. AddKeyBoardINput('F');
  518. }
  519. else if (e.Command == CmdG)
  520. {
  521. AddKeyBoardINput('G');
  522. }
  523. else if (e.Command == CmdH)
  524. {
  525. AddKeyBoardINput('H');
  526. }
  527. else if (e.Command == CmdJ)
  528. {
  529. AddKeyBoardINput('J');
  530. }
  531. else if (e.Command == CmdK)
  532. {
  533. AddKeyBoardINput('K');
  534. }
  535. else if (e.Command == CmdL)
  536. {
  537. AddKeyBoardINput('L');
  538. }
  539. else if (e.Command == CmdColon)
  540. {
  541. if (!ShiftFlag)
  542. {
  543. TouchScreenKeyboard.TouchScreenText += ";";
  544. }
  545. else
  546. {
  547. TouchScreenKeyboard.TouchScreenText += ":";
  548. ShiftFlag = false;
  549. }
  550. }
  551. else if (e.Command == CmdDoubleInvertedComma)
  552. {
  553. if (!ShiftFlag)
  554. {
  555. TouchScreenKeyboard.TouchScreenText += "'";
  556. }
  557. else
  558. {
  559. TouchScreenKeyboard.TouchScreenText += Char.ConvertFromUtf32(34);
  560. ShiftFlag = false;
  561. }
  562. }
  563. else if (e.Command == CmdEnter)
  564. {
  565. if (_instanceObject != null)
  566. {
  567. _instanceObject.Close();
  568. _instanceObject = null;
  569. }
  570. _currentControl.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
  571. }
  572. else if (e.Command == CmdShift) //Fourth Row
  573. {
  574. ShiftFlag = true; ;
  575. }
  576. else if (e.Command == CmdZ)
  577. {
  578. AddKeyBoardINput('Z');
  579. }
  580. else if (e.Command == CmdX)
  581. {
  582. AddKeyBoardINput('X');
  583. }
  584. else if (e.Command == CmdC)
  585. {
  586. AddKeyBoardINput('C');
  587. }
  588. else if (e.Command == CmdV)
  589. {
  590. AddKeyBoardINput('V');
  591. }
  592. else if (e.Command == CmdB)
  593. {
  594. AddKeyBoardINput('B');
  595. }
  596. else if (e.Command == CmdN)
  597. {
  598. AddKeyBoardINput('N');
  599. }
  600. else if (e.Command == CmdM)
  601. {
  602. AddKeyBoardINput('M');
  603. }
  604. else if (e.Command == CmdLessThan)
  605. {
  606. if (!ShiftFlag)
  607. {
  608. TouchScreenKeyboard.TouchScreenText += ",";
  609. }
  610. else
  611. {
  612. TouchScreenKeyboard.TouchScreenText += "<";
  613. ShiftFlag = false;
  614. }
  615. }
  616. else if (e.Command == CmdGreaterThan)
  617. {
  618. if (!ShiftFlag)
  619. {
  620. TouchScreenKeyboard.TouchScreenText += ".";
  621. }
  622. else
  623. {
  624. TouchScreenKeyboard.TouchScreenText += ">";
  625. ShiftFlag = false;
  626. }
  627. }
  628. else if (e.Command == CmdQuestion)
  629. {
  630. if (!ShiftFlag)
  631. {
  632. TouchScreenKeyboard.TouchScreenText += "/";
  633. }
  634. else
  635. {
  636. TouchScreenKeyboard.TouchScreenText += "?";
  637. ShiftFlag = false;
  638. }
  639. }
  640. else if (e.Command == CmdSpaceBar)//Last row
  641. {
  642. TouchScreenKeyboard.TouchScreenText += " ";
  643. }
  644. else if (e.Command == CmdClear)//Last row
  645. {
  646. TouchScreenKeyboard.TouchScreenText = "";
  647. }
  648. }
  649. private static void SetCommandBinding()
  650. {
  651. CommandBinding CbTlide = new CommandBinding(CmdTlide, RunCommand);
  652. CommandBinding Cb1 = new CommandBinding(Cmd1, RunCommand);
  653. CommandBinding Cb2 = new CommandBinding(Cmd2, RunCommand);
  654. CommandBinding Cb3 = new CommandBinding(Cmd3, RunCommand);
  655. CommandBinding Cb4 = new CommandBinding(Cmd4, RunCommand);
  656. CommandBinding Cb5 = new CommandBinding(Cmd5, RunCommand);
  657. CommandBinding Cb6 = new CommandBinding(Cmd6, RunCommand);
  658. CommandBinding Cb7 = new CommandBinding(Cmd7, RunCommand);
  659. CommandBinding Cb8 = new CommandBinding(Cmd8, RunCommand);
  660. CommandBinding Cb9 = new CommandBinding(Cmd9, RunCommand);
  661. CommandBinding Cb0 = new CommandBinding(Cmd0, RunCommand);
  662. CommandBinding CbMinus = new CommandBinding(CmdMinus, RunCommand);
  663. CommandBinding CbPlus = new CommandBinding(CmdPlus, RunCommand);
  664. CommandBinding CbBackspace = new CommandBinding(CmdBackspace, RunCommand);
  665. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbTlide);
  666. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb1);
  667. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb2);
  668. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb3);
  669. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb4);
  670. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb5);
  671. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb6);
  672. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb7);
  673. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb8);
  674. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb9);
  675. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cb0);
  676. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbMinus);
  677. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbPlus);
  678. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbBackspace);
  679. CommandBinding CbTab = new CommandBinding(CmdTab, RunCommand);
  680. CommandBinding CbQ = new CommandBinding(CmdQ, RunCommand);
  681. CommandBinding Cbw = new CommandBinding(Cmdw, RunCommand);
  682. CommandBinding CbE = new CommandBinding(CmdE, RunCommand);
  683. CommandBinding CbR = new CommandBinding(CmdR, RunCommand);
  684. CommandBinding CbT = new CommandBinding(CmdT, RunCommand);
  685. CommandBinding CbY = new CommandBinding(CmdY, RunCommand);
  686. CommandBinding CbU = new CommandBinding(CmdU, RunCommand);
  687. CommandBinding CbI = new CommandBinding(CmdI, RunCommand);
  688. CommandBinding Cbo = new CommandBinding(CmdO, RunCommand);
  689. CommandBinding CbP = new CommandBinding(CmdP, RunCommand);
  690. CommandBinding CbOpenCrulyBrace = new CommandBinding(CmdOpenCrulyBrace, RunCommand);
  691. CommandBinding CbEndCrultBrace = new CommandBinding(CmdEndCrultBrace, RunCommand);
  692. CommandBinding CbOR = new CommandBinding(CmdOR, RunCommand);
  693. CommandBinding CbCapsLock = new CommandBinding(CmdCapsLock, RunCommand);
  694. CommandBinding CbA = new CommandBinding(CmdA, RunCommand);
  695. CommandBinding CbS = new CommandBinding(CmdS, RunCommand);
  696. CommandBinding CbD = new CommandBinding(CmdD, RunCommand);
  697. CommandBinding CbF = new CommandBinding(CmdF, RunCommand);
  698. CommandBinding CbG = new CommandBinding(CmdG, RunCommand);
  699. CommandBinding CbH = new CommandBinding(CmdH, RunCommand);
  700. CommandBinding CbJ = new CommandBinding(CmdJ, RunCommand);
  701. CommandBinding CbK = new CommandBinding(CmdK, RunCommand);
  702. CommandBinding CbL = new CommandBinding(CmdL, RunCommand);
  703. CommandBinding CbColon = new CommandBinding(CmdColon, RunCommand);
  704. CommandBinding CbDoubleInvertedComma = new CommandBinding(CmdDoubleInvertedComma, RunCommand);
  705. CommandBinding CbEnter = new CommandBinding(CmdEnter, RunCommand);
  706. CommandBinding CbShift = new CommandBinding(CmdShift, RunCommand);
  707. CommandBinding CbZ = new CommandBinding(CmdZ, RunCommand);
  708. CommandBinding CbX = new CommandBinding(CmdX, RunCommand);
  709. CommandBinding CbC = new CommandBinding(CmdC, RunCommand);
  710. CommandBinding CbV = new CommandBinding(CmdV, RunCommand);
  711. CommandBinding CbB = new CommandBinding(CmdB, RunCommand);
  712. CommandBinding CbN = new CommandBinding(CmdN, RunCommand);
  713. CommandBinding CbM = new CommandBinding(CmdM, RunCommand);
  714. CommandBinding CbGreaterThan = new CommandBinding(CmdGreaterThan, RunCommand);
  715. CommandBinding CbLessThan = new CommandBinding(CmdLessThan, RunCommand);
  716. CommandBinding CbQuestion = new CommandBinding(CmdQuestion, RunCommand);
  717. CommandBinding CbSpaceBar = new CommandBinding(CmdSpaceBar, RunCommand);
  718. CommandBinding CbClear = new CommandBinding(CmdClear, RunCommand);
  719. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbTab);
  720. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbQ);
  721. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cbw);
  722. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbE);
  723. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbR);
  724. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbT);
  725. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbY);
  726. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbU);
  727. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbI);
  728. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), Cbo);
  729. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbP);
  730. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbOpenCrulyBrace);
  731. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbEndCrultBrace);
  732. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbOR);
  733. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbCapsLock);
  734. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbA);
  735. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbS);
  736. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbD);
  737. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbF);
  738. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbG);
  739. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbH);
  740. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbJ);
  741. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbK);
  742. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbL);
  743. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbColon);
  744. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbDoubleInvertedComma);
  745. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbEnter);
  746. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbShift);
  747. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbZ);
  748. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbX);
  749. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbC);
  750. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbV);
  751. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbB);
  752. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbN);
  753. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbM);
  754. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbGreaterThan);
  755. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbLessThan);
  756. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbQuestion);
  757. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbSpaceBar);
  758. CommandManager.RegisterClassCommandBinding(typeof(TouchScreenKeyboard), CbClear);
  759. }
  760. /// <summary>
  761. /// Syncs the child.
  762. /// </summary>
  763. private static void SyncChild()
  764. {
  765. if (_currentControl != null && _instanceObject != null)
  766. {
  767. Point virtualpoint = new Point(0, _currentControl.ActualHeight + 3);
  768. Point Actualpoint = _currentControl.PointToScreen(virtualpoint);
  769. if (WidthTouchKeyboard + Actualpoint.X > SystemParameters.VirtualScreenWidth)
  770. {
  771. double difference = WidthTouchKeyboard + Actualpoint.X - SystemParameters.VirtualScreenWidth;
  772. _instanceObject.Left = Actualpoint.X - difference;
  773. }
  774. else if (!(Actualpoint.X > 1))
  775. {
  776. _instanceObject.Left = 1;
  777. }
  778. else
  779. {
  780. _instanceObject.Left = Actualpoint.X;
  781. }
  782. _instanceObject.Top = Actualpoint.Y;
  783. _instanceObject.Show();
  784. }
  785. }
  786. static void TouchScreenKeyboardPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
  787. {
  788. FrameworkElement host = sender as FrameworkElement;
  789. if (host != null)
  790. {
  791. host.GotFocus += new RoutedEventHandler(OnGotFocus);
  792. host.Unloaded += OnUnloaded;
  793. host.LostFocus += new RoutedEventHandler(OnLostFocus);
  794. }
  795. }
  796. static void TouchScreenKeyboard_Activated(object sender, EventArgs e)
  797. {
  798. if (_instanceObject != null)
  799. {
  800. _instanceObject.Topmost = true;
  801. }
  802. }
  803. static void TouchScreenKeyboard_Deactivated(object sender, EventArgs e)
  804. {
  805. if (_instanceObject != null)
  806. {
  807. _instanceObject.Topmost = false;
  808. }
  809. }
  810. #endregion Methods
  811. }
  812. }