Klavyeden data kontrol.

erciyes38

Üye
Katılım
15 Ara 2011
Mesajlar
63
Puanları
1
Klavyenin yön tuşları ile seri porta (eğer oluyorsa usb'de olur) 4 farklı komut (her yön tuşu ayrı bir komut) göndermek için bir program arıyorum. Bilgisi olan arkadaşlar yardımınızı bekliyorum.
 
En basitinden Visula basic ile bir program hazırlayıp yön tuşlarını kullanabilirsiniz.
Burada asıl önemli nokta sizin bu komutları seri port veya usb üzerinde alıp işi yapacak devreyi yapmanız. Bu iş için pic kullanmanız gerekmekte.
 
PIC kısmını halledebilirim, benim aradığım yön tuşlarından portlara komut gönderen bir program.
 
Merhaba,

Aşağıda verdiğim kodlar ile bu işe yapabilirsin!

Projede 2 form olacak. Bunlardan birincisinde Comport ayarları yapılacak, ikincisinde ise tuşları gösteren işaretler bulunacak. Tuşlar bu ikinci form açıkken kullanılabilecek. Yani önce form1 açılır, sonrada kullanacağımız comport seçilir ensonda başla butonu ile 2.form açılır. Buradanda yön tuşlarına klavyeden basarak, seriporttan ilgili tuş için yazdığımız bilgi gönderilir.

Not : Ben PictureBoxlara image olarak okları ekledim senden benzer birşey yaparsan görsellik artar.

1. formdaki nesneler;

Label2
Combobox1
Button1
Button2

2.formdaki nesneler;

Picturebox1
Picturebox2
Picturebox3
Picturebox4
Label1
Serialport1

Kodlara gelince;

Form1
Kod:
Public Class Form1
PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
Form2.Label1.Text = "------"
Button1.Enabled = True
Button2.Enabled = False
ComboBox1.Enabled = True
EndSub
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text = ""Then
MsgBox("ComPort Kutusu Boş Olamaz! Bir ComPort Seçiniz", MsgBoxStyle.Exclamation, "Uyarı")
ComboBox1.Focus()
Else
Form2.SerialPort1.PortName = ComboBox1.Text
Form2.SerialPort1.Open()
ComboBox1.Enabled = False
Button2.Enabled = True
Button1.Enabled = False
Form2.Show()
Form2.Select()
EndIf
EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.SerialPort1.Close()
ComboBox1.Enabled = True
Button1.Enabled =True
Button2.Enabled = False
EndSub
EndClass


Form2
Kod:
Imports System.IO
Imports System.Windows.Forms
PublicClass Form2

PrivateSub Form2_KeyDown(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyEventArgs) HandlesMe.KeyDown
If SerialPort1.IsOpen = FalseThen
MsgBox("ComPort Kapalı! Başla Düğmesi ile ComPortu Açmalısınız?", MsgBoxStyle.Exclamation, "Uyarı")
ExitSub
Else
If e.KeyCode = Keys.Up Then
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
PictureBox4.Visible = False
Label1.Text = " UP "
SerialPort1.Write(Label1.Text)
EndIf
If e.KeyCode = Keys.Right Then
PictureBox2.Visible = True
PictureBox1.Visible = False
PictureBox3.Visible = False
PictureBox4.Visible = False
Label1.Text = " RIGHT > "
SerialPort1.Write(Label1.Text)
EndIf
If e.KeyCode = Keys.Down Then
PictureBox3.Visible = True
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox4.Visible = False
Label1.Text = " DOWN "
SerialPort1.Write(Label1.Text)
EndIf
If e.KeyCode = Keys.Left Then
PictureBox4.Visible = True
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = False
Label1.Text = " < LEFT "
SerialPort1.Write(Label1.Text)
EndIf
EndIf
EndSub
EndClass
 

Forum istatistikleri

Konular
127,956
Mesajlar
913,899
Kullanıcılar
449,606
Son üye
rasit.

Yeni konular

Çevrimiçi üyeler

Geri
Üst