ExclamationSimulate a Key Press

Posts 12 of 2 · Page 1 of 1
Simulate a Key Press
Alright. Before you spam me with "Use SendKeys.Send()", please understand, I have already tried it and it does not fill my needs.

So I'm playing a game (Allods) and I'm trying to use my xb360 controller with it. Problem is, the game doesn't want to take the keys from the controller. However, if i press a key on the keyboard, and then try the controller, it works just fine.

So my solution was so make a program that spams the unused J key so i can openly use my controller. This is the code i tried, which does it's job successfully for spamming the J key, but does not work in game. It'll work in chat and such, but still does not open up controller functionality.

Source Code:
Code:
Public Class Form1
    Public Declare Function GetAsyncKeyState Lib "User32" (ByVal vKey As Long) As Integer
    Dim already As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = False
        Timer2.Enabled = False
        Dim start As DateTime = Now.AddMilliseconds(500)
        Do
            Application.DoEvents()
        Loop Until Now > start
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim hotkey1 As Boolean = GetAsyncKeyState(Keys.F7)
        Dim hotkey2 As Boolean = GetAsyncKeyState(Keys.F8)
        If hotkey1 = True And already = 0 Then
            already = 1
            If Timer2.Enabled = True Then
                Timer2.Enabled = False
            ElseIf Timer2.Enabled = False Then
                Timer2.Enabled = True
            End If
        ElseIf hotkey1 = False And already = 1 Then
            already = 0
        End If
        If hotkey2 = True Then
            Application.Exit()
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        SendKeys.Send("j")
    End Sub
End Class
Therefor, forum, i'm asking if any of you know an alternate way to "spam" the j key besides sendkeys.send.

Much Appreciation,
Gwen Travolta
You can use the virtual keypress API that FLAMESABER told me about.

Gimme a sec lemme see if I remembered to save it :S

EDIT: Okay here we go, I couldn't find FLAMESABER's example so I googled quickly and wrote my "own"

Declarations:

[php]
Public Declare Function keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long) As Long

Const KEYEVENTF_KEYUP = &H2
[/php]

Now add this sub:

[php]
Private Sub press(ByVal mykey As Keys)

keybd_event(mykey, 0, 0, 0)
keybd_event(mykey, 0, KEYEVENTF_KEYUP, 0)

End Sub
[/php]

Then whenever you need to simulate a key press write this

[php]

press(Keys.J) 'change Keys.J to Keys.XXXX whatever you want'

[/php]

That should about do it.
Posts 12 of 2 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?