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.Windows.Forms;
- namespace Mlaker
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Left)
- {
- Poslji(2);
- }
- else if (e.KeyCode == Keys.Right)
- {
- Poslji(1);
- }
- else if (e.KeyCode == Keys.Up)
- {
- Poslji(4);
- }
- else if (e.KeyCode == Keys.Down)
- {
- Poslji(3);
- }
- else if (e.KeyCode == Keys.Space)
- {
- Poslji(9);
- }
- else if (e.KeyCode == Keys.ShiftKey)
- {
- Poslji(20);
- }
- }
- void Poslji(byte poslji)
- {
- try
- {
- byte[] b = new byte[1];
- b[0] = poslji;
- serialPort1.Write(b, 0, 1);
- }
- catch
- {
- MessageBox.Show("Napaka pri posiljanju");
- }
- }
- private void buttonOdpri_Click(object sender, EventArgs e)
- {
- if (buttonOdpri.Text == "Odpri")
- {
- serialPort1.PortName = textBoxPort.Text;
- serialPort1.BaudRate = int.Parse(textBoxHitrost.Text);
- serialPort1.Open();
- buttonOdpri.Text = "Zapri";
- }
- else
- {
- serialPort1.Close();
- buttonOdpri.Text = "Odpri";
- }
- }
- private void Form1_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Left)
- {
- Poslji(6);
- }
- else if (e.KeyCode == Keys.Right)
- {
- Poslji(5);
- }
- else if (e.KeyCode == Keys.Up)
- {
- Poslji(8);
- }
- else if (e.KeyCode == Keys.Down)
- {
- Poslji(7);
- }
- else if (e.KeyCode == Keys.Space)
- {
- Poslji(10);
- }
- else if (e.KeyCode == Keys.ShiftKey)
- {
- Poslji(21);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment