|
-
Jan 27th, 2007, 09:20 PM
#1
Thread Starter
Hyperactive Member
Simulate Key Strokes
I am writing a program for a customer that takes thier database every night and exports the on hand amount and interacts with thier website to change the qty. (This part is not a problem)
The issue I need to solve is automation of exporting the data. The database is encrytped and the only way to export the data is from inside the software (RICS if anyone has ever delt with this program.) The only solution I can think of is to simulate key strokes through my program and export the data every night. Can this be done? If so how? Or can anyone think of a better method?
Thanks!
Anjari
-
Jan 27th, 2007, 11:00 PM
#2
Lively Member
Re: Simulate Key Strokes
I wrote a custom control for a PocketPC app to do just this (after many days of searching how). The code should be the same or similar for any vb app. My code is below. Basically, I have 12 panels alligned in a 4x3 layout, with each panel having a label, labeled 0, 1-9, ., and Tab (which looks like a keypad)
When the panel.click event fires, I have the code send the needed character to a sub that simulates the keyboard event. If this is not clear, let me know and I can explain more.
VB Code:
Imports System.Runtime.InteropServices
Public Class KeypadControl
<DllImport("coredll")> Public Shared Sub keybd_event(ByVal vk As Byte, ByVal sc As Byte, ByVal Flags As Integer, ByVal dwExtraInfo As Integer)
End Sub
Public Sub SendKBChar(ByVal ch As Char)
If ch = "." Then
keybd_event(&HBE, 0, 0, 0)
keybd_event(&HBE, 0, &H2, 0)
ElseIf ch = "T" Then
keybd_event(9, 0, 0, 0)
keybd_event(9, 0, &H2, 0)
Else
Dim vk As Byte
vk = BitConverter.GetBytes(ch)(0) 'convert character to unicode
keybd_event(vk, 0, 0, 0)
keybd_event(vk, 0, &H2, 0)
End If
End Sub
Private Sub Panel1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Click
SendKBChar("1")
End Sub
Private Sub Panel2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel2.Click
SendKBChar("2")
End Sub
Private Sub Panel3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel3.Click
SendKBChar("3")
End Sub
Private Sub Panel4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel4.Click
SendKBChar("4")
End Sub
Private Sub Panel5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel5.Click
SendKBChar("5")
End Sub
Private Sub Panel6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel6.Click
SendKBChar("6")
End Sub
Private Sub Panel10_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel10.Click
SendKBChar("0")
End Sub
Private Sub Panel7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel7.Click
SendKBChar("7")
End Sub
Private Sub Panel8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel8.Click
SendKBChar("8")
End Sub
Private Sub Panel9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel9.Click
SendKBChar("9")
End Sub
Private Sub Panel10_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel11.Click
SendKBChar(".")
End Sub
Private Sub Panel12_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel12.Click
SendKBChar("T") 'sends tab key, not T
End Sub
End Class
-
Jan 28th, 2007, 12:01 AM
#3
Thread Starter
Hyperactive Member
Re: Simulate Key Strokes
I guess I should have stated this earlier. I would need to send keyboard commands to another program that is running.... Wouldnt I need to drop focus on my program?
-
Jan 28th, 2007, 03:24 AM
#4
Re: Simulate Key Strokes
That's why I made SendKeysToWindow
Hope it works in your situation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|