Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2013, 10:58 PM
edburchell edburchell is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 edburchell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 33 sec
Reputation 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.

Reply With Quote
  #2  
Old March 7th, 2013, 01:24 PM
Night1505 Night1505 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 5 Night1505 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 52 m
Reputation 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

Reply With Quote
  #3  
Old March 29th, 2013, 07:56 AM
necproi necproi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 13 necproi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 47 m 35 sec
Warnings Level: 5
Reputation Power: 0
Hello

Quote:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Need anyone's help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap