Advertisement
Guest User

Untitled

a guest
Aug 11th, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Exemplo_teclado_simples
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20. private void teclado(object sender, KeyEventArgs e)
  21. {
  22. try
  23. {
  24. Porta.Open();
  25. if (e.KeyCode == Keys.Up)
  26. {
  27. Porta.Write("U");
  28. Text = "Up";
  29. }
  30. if (e.KeyCode == Keys.Down)
  31. {
  32. Porta.Write("D");
  33. Text = "Down";
  34. }
  35. if (e.KeyCode == Keys.Right)
  36. {
  37. Porta.Write("R");
  38. Text = "Right";
  39. }
  40. if (e.KeyCode == Keys.Left)
  41. {
  42. Porta.Write("L");
  43. Text = "Left";
  44. }
  45. Porta.Close();
  46. }
  47. catch
  48. {
  49. Text = "Erro na comunicação";
  50. }
  51. }
  52.  
  53. private void detectar_tecla(object sender, PreviewKeyDownEventArgs e)
  54. {
  55. if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
  56. {
  57. e.IsInputKey = true;
  58. }
  59.  
  60. }
  61.  
  62. private void button1_Click(object sender, EventArgs e)
  63. {
  64. try
  65. {
  66. Porta.Open();
  67. Porta.Write("U");
  68. Text = "Up";
  69. Porta.Close();
  70. }
  71. catch
  72. {
  73. Text = "Erro na comunicação";
  74. }
  75.  
  76. }
  77.  
  78. private void button2_Click(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. Porta.Open();
  83. Porta.Write("L");
  84. Text = "Left";
  85. Porta.Close();
  86. }
  87. catch
  88. {
  89. Text = "Erro na comunicação";
  90. }
  91. }
  92.  
  93. private void button4_Click(object sender, EventArgs e)
  94. {
  95. try
  96. {
  97. Porta.Open();
  98. Porta.Write("D");
  99. Text = "Down";
  100. Porta.Close();
  101. }
  102. catch
  103. {
  104. Text = "Erro na comunicação";
  105. }
  106. }
  107.  
  108. private void button3_Click(object sender, EventArgs e)
  109. {
  110. try
  111. {
  112. Porta.Open();
  113. Porta.Write("R");
  114. Text = "Right";
  115. Porta.Close();
  116. }
  117. catch
  118. {
  119. Text = "Erro na comunicação";
  120. }
  121. }
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement