Results 1 to 4 of 4

Thread: Simulate Key Strokes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    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

  2. #2
    Lively Member
    Join Date
    Jan 2007
    Location
    Austin, TX
    Posts
    120

    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:
    1. Imports System.Runtime.InteropServices
    2.  
    3.  
    4. Public Class KeypadControl
    5.  
    6.  
    7.     <DllImport("coredll")> Public Shared Sub keybd_event(ByVal vk As Byte, ByVal sc As Byte, ByVal Flags As Integer, ByVal dwExtraInfo As Integer)
    8.     End Sub
    9.  
    10.     Public Sub SendKBChar(ByVal ch As Char)
    11.         If ch = "." Then
    12.             keybd_event(&HBE, 0, 0, 0)
    13.             keybd_event(&HBE, 0, &H2, 0)
    14.         ElseIf ch = "T" Then
    15.             keybd_event(9, 0, 0, 0)
    16.             keybd_event(9, 0, &H2, 0)
    17.         Else
    18.             Dim vk As Byte
    19.             vk = BitConverter.GetBytes(ch)(0) 'convert character to unicode
    20.             keybd_event(vk, 0, 0, 0)
    21.             keybd_event(vk, 0, &H2, 0)
    22.         End If
    23.  
    24.     End Sub
    25.  
    26.     Private Sub Panel1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Click
    27.         SendKBChar("1")
    28.     End Sub
    29.  
    30.     Private Sub Panel2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel2.Click
    31.         SendKBChar("2")
    32.  
    33.     End Sub
    34.     Private Sub Panel3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel3.Click
    35.         SendKBChar("3")
    36.  
    37.     End Sub
    38.  
    39.     Private Sub Panel4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel4.Click
    40.         SendKBChar("4")
    41.  
    42.     End Sub
    43.  
    44.     Private Sub Panel5_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel5.Click
    45.         SendKBChar("5")
    46.  
    47.     End Sub
    48.  
    49.     Private Sub Panel6_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel6.Click
    50.         SendKBChar("6")
    51.  
    52.     End Sub
    53.  
    54.     Private Sub Panel10_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel10.Click
    55.         SendKBChar("0")
    56.  
    57.     End Sub
    58.  
    59.     Private Sub Panel7_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel7.Click
    60.         SendKBChar("7")
    61.  
    62.     End Sub
    63.  
    64.     Private Sub Panel8_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel8.Click
    65.         SendKBChar("8")
    66.  
    67.     End Sub
    68.  
    69.     Private Sub Panel9_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel9.Click
    70.         SendKBChar("9")
    71.  
    72.     End Sub
    73.  
    74.     Private Sub Panel10_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel11.Click
    75.         SendKBChar(".")
    76.  
    77.     End Sub
    78.  
    79.     Private Sub Panel12_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel12.Click
    80.         SendKBChar("T") 'sends tab key, not T
    81.  
    82.     End Sub
    83.  
    84.    
    85. End Class

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2002
    Location
    Canton, GA
    Posts
    487

    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?

  4. #4

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