Simulate up/down/left/right

R

Roger McFadden

Hello

I want to simulate up/down/left/right-keys.

I have this code:

Public Const KEYEVENTF_UP As Integer = &H2

Public Const KEYEVENTF_EXTENDKEY As Integer = &H1

Public Const KEYEVENTF_SILENT As Integer = &H4

<DllImport("coredll.dll")> _

Public Shared Sub keybd_event( _

ByVal bVk As Byte, _

ByVal bScan As Byte, _

ByVal dwFlags As Integer, _

ByVal dwExtraInfo As Integer)

End Sub

Public Sub PressKey(ByVal key As Keys)

Dim code As Byte = CType(key, Byte)

Dim up As Integer = KEYEVENTF_UP

Try

keybd_event(code, 0, 0, 0) 'keydown

keybd_event(code, 0, up, 0) 'keyup

Catch ex As Exception

End Try

End Sub



Now if I use PressKey(Keys.A), then I get an "a", globally

If I use PressKey(Keys.Up) (or down/left/right), it does nothing, but my PPC slows down ..



Whats wrong?
 
P

Paul G. Tobey [eMVP]

Sorry, I don't read VB code very quickly. You want to send what key? For
alphabetic keys *don't* use keybd_event(). Use PostKeybdMessage() for that
case. If you need to send Tab or CR or Backspace, use keybd_event().

Paul T.

-----

"Roger McFadden" <-> wrote in message
Hello

I want to simulate up/down/left/right-keys.

I have this code:

Public Const KEYEVENTF_UP As Integer = &H2
Public Const KEYEVENTF_EXTENDKEY As Integer = &H1
Public Const KEYEVENTF_SILENT As Integer = &H4
<DllImport("coredll.dll")> _
Public Shared Sub keybd_event( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Integer, _
ByVal dwExtraInfo As Integer)
End Sub
Public Sub PressKey(ByVal key As Keys)
Dim code As Byte = CType(key, Byte)
Dim up As Integer = KEYEVENTF_UP
Try
keybd_event(code, 0, 0, 0) 'keydown
keybd_event(code, 0, up, 0) 'keyup
Catch ex As Exception
End Try
End Sub

Now if I use PressKey(Keys.A), then I get an "a", globally
If I use PressKey(Keys.Up) (or down/left/right), it does nothing, but my PPC
slows down ..

Whats wrong?
 
R

Roger McFadden

Hi Paul

I want to simulate the Up / Down / Left and Right (Joystick on
Smartphone)-Keys

I can simulate the left/right softkeys, I can simulate all alphabetic keys
(with keybd_event) but I cannot simulate the joystick :-(



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> schrieb im Newsbeitrag news:[email protected]...
 
P

Paul G. Tobey [eMVP]

If it's the arrow keys, you can try sending VK_UP, etc. You'll have to
verify that Keys.<whatever> gives the right values for those. You'll want
to send the down, then the up, of course. Don't have a SmartPhone, so I
can't tell you what the 'joystick' sends. It's definitely a key device and
not a mouse device?

If you send alphabetic keys via keybd_event(), you will probably end up with
problems, eventually. If so, remember PostKeybdMessage...

Paul T.

Roger McFadden said:
Hi Paul

I want to simulate the Up / Down / Left and Right (Joystick on
Smartphone)-Keys

I can simulate the left/right softkeys, I can simulate all alphabetic keys
(with keybd_event) but I cannot simulate the joystick :-(



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> schrieb im Newsbeitrag news:[email protected]...
Sorry, I don't read VB code very quickly. You want to send what key?
For alphabetic keys *don't* use keybd_event(). Use PostKeybdMessage()
for that case. If you need to send Tab or CR or Backspace, use
keybd_event().

Paul T.

-----

"Roger McFadden" <-> wrote in message
Hello

I want to simulate up/down/left/right-keys.

I have this code:

Public Const KEYEVENTF_UP As Integer = &H2
Public Const KEYEVENTF_EXTENDKEY As Integer = &H1
Public Const KEYEVENTF_SILENT As Integer = &H4
<DllImport("coredll.dll")> _
Public Shared Sub keybd_event( _
ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Integer, _
ByVal dwExtraInfo As Integer)
End Sub
Public Sub PressKey(ByVal key As Keys)
Dim code As Byte = CType(key, Byte)
Dim up As Integer = KEYEVENTF_UP
Try
keybd_event(code, 0, 0, 0) 'keydown
keybd_event(code, 0, up, 0) 'keyup
Catch ex As Exception
End Try
End Sub

Now if I use PressKey(Keys.A), then I get an "a", globally
If I use PressKey(Keys.Up) (or down/left/right), it does nothing, but my
PPC slows down ..

Whats wrong?
 

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

Top