Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keyboard control

Status
Not open for further replies.

arkomnv

Programmer
May 22, 2006
14
BE
could any1 give me a code example or a link


about how i can control a button click event with a keypress on my keyboard


i am trying to make a screen keyboard that can be countrolled with the mouse but if a lettre or number on the keyboard is pressed i would like to handle the some line of code

i tryed to make it work with a override sub but it didnot work

could some1 pls help me out


THX
 
To catch keys pressed, no matter what control has the focus, set the keypreview property of the form to true and write code in the appropriate event handler of the form.
 
could you give me a little code example on that code


thx
 
First, i need to ask:
> If you click with the mouse a button (e.g. "d") you want to do something like: textbox1.text &= button_d.text ?

 
Hi, i dont know if this is 100% formated the right way, but it should work.

- Anti


Public Class Form1

Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.A Then
If TextBox1.Text = String.Empty Then
TextBox1.Text = "a"
Else
TextBox1.Text = TextBox1.Text & "a"
End If
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.KeyPreview = True
End Sub


End Class
 
Forgot to say what im doing:

1. I set Keypreview = true in the form1_load event so the form will look for buttons pressed on the keyboard, else it will ignore it and let controls on the form react.

2. I create a Form1 event called KeyUp. It the event that will fire if a key is pressed. Next i say if the "a" button is pressed it should write a "a" in the textbox.

KeyUp only fires when a key is released
KeyDown fires when the key is pressed down.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top