Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Exemplo_teclado_simples
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void teclado(object sender, KeyEventArgs e)
- {
- try
- {
- Porta.Open();
- if (e.KeyCode == Keys.Up)
- {
- Porta.Write("U");
- Text = "Up";
- }
- if (e.KeyCode == Keys.Down)
- {
- Porta.Write("D");
- Text = "Down";
- }
- if (e.KeyCode == Keys.Right)
- {
- Porta.Write("R");
- Text = "Right";
- }
- if (e.KeyCode == Keys.Left)
- {
- Porta.Write("L");
- Text = "Left";
- }
- Porta.Close();
- }
- catch
- {
- Text = "Erro na comunicação";
- }
- }
- private void detectar_tecla(object sender, PreviewKeyDownEventArgs e)
- {
- if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
- {
- e.IsInputKey = true;
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- Porta.Open();
- Porta.Write("U");
- Text = "Up";
- Porta.Close();
- }
- catch
- {
- Text = "Erro na comunicação";
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- Porta.Open();
- Porta.Write("L");
- Text = "Left";
- Porta.Close();
- }
- catch
- {
- Text = "Erro na comunicação";
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- try
- {
- Porta.Open();
- Porta.Write("D");
- Text = "Down";
- Porta.Close();
- }
- catch
- {
- Text = "Erro na comunicação";
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- try
- {
- Porta.Open();
- Porta.Write("R");
- Text = "Right";
- Porta.Close();
- }
- catch
- {
- Text = "Erro na comunicação";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement