Reading from Keyboard

  • Thread starter Thread starter Zyrthofar Blackcloak
  • Start date Start date
Z

Zyrthofar Blackcloak

Hi

I need to get every keys pressed at one time, without needing a
triggered event.

Control.ModifierKeys works perfectly for shift, ctrl and alt, but how
can I check other keys like the letters and arrows?

I quickly checked VB2005, and found out the control class doesn't have
anything either...


Any hint at something that would similarly work like
Control.ModifierKeys would greatly be appreciated.
Also, if the method would detect combinations like UpArrow+LeftArrow
(combinations without modifier keys), that would be even better. :)

Thanks
 
Pop this code into you app and see what happens. Set the KeyPreview
property of the form to True to trap the keypress events.

Not sure if this is what you want.
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

TextBox1.Text = e.KeyChar

End Sub
 
* Zyrthofar Blackcloak said:
I need to get every keys pressed at one time, without needing a
triggered event.

Control.ModifierKeys works perfectly for shift, ctrl and alt, but how
can I check other keys like the letters and arrows?

I quickly checked VB2005, and found out the control class doesn't have
anything either...

..NET 1.1 doesn't provide a managed way to determine if a key is pressed or
not except for modifier keys ('Control.ModifierKeys'). 'GetAsyncKeyState'
can be used to determine if a key is pressed:

\\\
Imports System.Windows.Forms
..
..
..
Private Declare Auto Function GetAsyncKeyState Lib "user32.dll" ( _
ByVal nVirtKey As Keys _
) As Boolean
///

Usage:

\\\
If GetAsyncKeyState(Keys.A) Then
...
End If
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top