#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Need anyone's help


    Its been a long time since I coded in VB and I'll explain what I want it to do before I copy my code

    This program will actually simulate a refuel for a slot car track. I use a motion detection software to detect a motion in a hotspot and trigger an event. That "event" would then be sent to my slotcar software which reads it as a keypress for lap times. This works well, there are no problems there...BUT my slotcar software needs a keypress and hold (namely the A button) in order for the refuel to start. My motion detection only triggers a keypress....not a keypress and hold. So what I wanted was a simple exe program that when the motion is detected it is run and simulates the A button being pressed and held for a certain amount of time, then released.

    Don't know if I am going in the right direction here but this is the code I have:

    Public Class Lane1test

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim wshshell As Object
    wshshell = CreateObject("WScript.Shell")
    Dim wsh As Object = CreateObject("WScript.Shell")

    'Using WScript to execute Stuff
    wsh = CreateObject("WScript.Shell")
    ' Open URWebCam.exe
    wshshell.Run("c:\Documents and Settings\ed\Desktop\Racer30\URWebCam.exe", 9)

    ' Give URWebCam time to load
    wsh.Sleep(500)

    'keypress the A button
    WshShell.SendKeys("a")
    Me.Close()
    End Sub

    End Class

    Could anyone please help me.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    5
    Rep Power
    0
    Have you tried putting your SendKeys("a") in a loop for a certain time? I mean, I know it sounds kinda silly, but all a "key hold" really is, is a series of repeated key presses.

    Maybe try putting the call to SendKeys in a Timer Control's Tick event, and set the tick interval to like 100ms or something. Then, for say a 10 second key hold, run the Timer Control for 100 Ticks.

    Perhaps something like:

    Public Class Lane1test

    Public ticks As Integer = 0
    Public wshshell As Object

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    wshshell = CreateObject("WScript.Shell")
    Dim wsh As Object = CreateObject("WScript.Shell")

    'Using WScript to execute Stuff
    wsh = CreateObject("WScript.Shell")
    ' Open URWebCam.exe
    wshshell.Run("c:\Documents and Settings\ed\Desktop\Racer30\URWebCam.exe", 9)

    ' Give URWebCam time to load
    wsh.Sleep(500)

    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'keypress the A button
    wshshell.SendKeys("a")

    If ticks > 100 Then
    Timer1.Stop()
    Me.Close()
    End If

    ticks += 1
    End Sub
    End Class
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    14
    Rep Power
    0

    Hello


    Originally Posted by Night1505
    Have you tried putting your SendKeys("a") in a loop for a certain time? I mean, I know it sounds kinda silly, but all a "key hold" really is, is a series of repeated key presses.

    Maybe try putting the call to SendKeys in a Timer Control's Tick event, and set the tick interval to like 100ms or something. Then, for say a 10 second key hold, run the Timer Control for 100 Ticks.

    Perhaps something like:

    Public Class Lane1test

    Public ticks As Integer = 0
    Public wshshell As Object

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    wshshell = CreateObject("WScript.Shell")
    Dim wsh As Object = CreateObject("WScript.Shell")

    'Using WScript to execute Stuff
    wsh = CreateObject("WScript.Shell")
    ' Open URWebCam.exe
    wshshell.Run("c:\Documents and Settings\ed\Desktop\Racer30\URWebCam.exe", 9)

    ' Give URWebCam time to load
    wsh.Sleep(500)

    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'keypress the A button
    wshshell.SendKeys("a")

    If ticks > 100 Then
    Timer1.Stop()
    Me.Close()
    End If

    ticks += 1
    End Sub
    End Class
    Hello,
    The idea is not bad, but it probably will not work. in this way, it all depends on the speed of computers and the results could be very bad.

IMN logo majestic logo threadwatch logo seochat tools logo