Results 1 to 2 of 2

Thread: cant emulate buttons on my application

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    5

    cant emulate buttons on my application

    Hey guys i can not get my keys to show up on MAME, it sends over the letters but it wont recognize an actual button push.
    Code:
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
        
    
    Private Type POINTAPI
        x As Long
        y As Long
        v1 As Long
        z As Long
        
    End Type
    Private Function GetCursorPosEx() As POINTAPI
    GetCursorPos GetCursorPosEx
    End Function
    
    
    Private Sub Timer1_Timer()
    With GetCursorPosEx
       ' Dim v1 As Integer
        x = .x
        'y = "Current Y = " & .y
        'z = "currect X = " & v1
        End With
        End Sub
    
    Private Sub Timer2_Timer()
    AppActivate "MAME"
    With GetCursorPosEx
        z = .x
        Dim sy As Integer
        Dim sz As Integer
        'If z = .x Then
        Text1.Text = x
        If z = Text1.Text Then
        y = "Scratch Me!"
        ElseIf z > Text1.Text Then
        y = "Greater"
    
    ' and then you can use this:
    SendKeys "{k}"
        ElseIf z < Text1.Text Then
        y = "smaller"
        SendKeys "{l}"
        Else
       End If
    End With
    End Sub
    any ideas???

  2. #2
    New Member c080's Avatar
    Join Date
    Oct 2013
    Posts
    11

    Thumbs up Re: cant emulate buttons on my application

    Quote Originally Posted by dcwhat View Post
    Hey guys i can not get my keys to show up on MAME, it sends over the letters but it wont recognize an actual button push.
    any ideas???
    Hey DC

    I wouldnt recommend using a timer for that.
    There are many ways you could do this but i have made something for you.
    Feel happy atleast cause i did spend a good 15 on this for you.

    Reference DirectX
    Make Form1 and 2 Textboxes 1 and 2 and a Module to test.
    All works. Up down left and right arrow keys move mouse.
    Escape exits. Make any key do whatever you like.
    Review. And alter to your specs.

    Within Form1 put.

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    ProgramOn = True
    TheLoop
    End Sub
    
    Private Sub Form_UnLoad(Cancel As Integer)
    End
    End Sub
    Within Module1 put.

    Code:
    Option Explicit
    
    Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    
    Global Const KEY_TOGGLED As Integer = &H1
    Global Const KEY_DOWN As Integer = &H1000
    
    Public DX As New DirectX7
    
    Public Type POINTAPI
    X As Long
    Y As Long
    End Type
    Public MousePos As POINTAPI
    
    Public ProgramOn As Boolean
    
    Public Sub UnLoadProgram()
    ProgramOn = False
    Unload Form1
    End Sub
    
    Public Sub Delay()
    Form1.Text1.Text = DX.TickCount
    Form1.Text2.Text = DX.TickCount + 1
    DoEvents
    Do Until DX.TickCount > Form1.Text2.Text
    Form1.Text1.Text = DX.TickCount
    Loop
    DoEvents
    End Sub
    
    Public Sub TheLoop()
    
    Form1.Visible = True
    
    Do While ProgramOn = True
    GetMousePos
    ControlsLoop
    Delay
    Loop
    DoEvents
    
    UnLoadProgram
    End Sub
    
    Public Sub GetMousePos()
    GetCursorPos MousePos
    Form1.Caption = "Mouse.X :" & MousePos.X & " " & "Mouse.Y :" & MousePos.Y
    DoEvents
    End Sub
    
    Public Sub ControlsLoop()
    
    If (GetKeyState(vbKeyEscape) And KEY_DOWN) Then
    UnLoadProgram
    Else
    End If
    
    If (GetKeyState(vbKeyUp) And KEY_DOWN) Then
    SetCursorPos MousePos.X, MousePos.Y - 1
    Else
    End If
    
    If (GetKeyState(vbKeyDown) And KEY_DOWN) Then
    SetCursorPos MousePos.X, MousePos.Y + 1
    Else
    End If
    
    If (GetKeyState(vbKeyLeft) And KEY_DOWN) Then
    SetCursorPos MousePos.X - 1, MousePos.Y
    Else
    End If
    
    If (GetKeyState(vbKeyRight) And KEY_DOWN) Then
    SetCursorPos MousePos.X + 1, MousePos.Y
    Else
    End If
    
    If (GetKeyState(vbKeyA) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeyB) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeyC) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeyL) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeyY) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeyZ) And KEY_DOWN) Then
    
    Else
    End If
    
    If (GetKeyState(vbKeySpace) And KEY_DOWN) Then
    
    Else
    End If
    
    DoEvents
    
    End Sub

    Now you wouldnt have to reference DX If you changed the tickcount section of the delay sub.
    But..... Dx is great for many things.

    Hope this was helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width