Problem in simulate keyboard event


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem in simulate keyboard event

Hybrid View

  1. #1
    Dasensa Esente Guest

    Problem in simulate keyboard event


    Hi, I am trying to simulate keyboard event using SendInput API.
    I found a code and tried it, and it works until now.
    The code can be found at www.allapi.net.
    Here it is:

    Const VK_H = 72 'Capital H
    Const VK_E = 69 'Capital E
    Const VK_L = 76 'Capital L
    Const VK_O = 79 'Capital O
    Const KEYEVENTF_KEYUP = &H2
    Const INPUT_MOUSE = 0
    Const INPUT_KEYBOARD = 1
    Const INPUT_HARDWARE = 2
    Private Type MOUSEINPUT
    dx As Long
    dy As Long
    mouseData As Long
    dwFlags As Long
    time As Long
    dwExtraInfo As Long
    End Type
    Private Type KEYBDINPUT
    wVk As Integer
    wScan As Integer
    dwFlags As Long
    time As Long
    dwExtraInfo As Long
    End Type
    Private Type HARDWAREINPUT
    uMsg As Long
    wParamL As Integer
    wParamH As Integer
    End Type
    Private Type GENERALINPUT
    dwType As Long
    xi(0 To 23) As Byte
    End Type
    Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long,
    pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst
    As Any, pSrc As Any, ByVal ByteLen As Long)
    Private Sub Form_KeyPress(KeyAscii As Integer)
    'Print the key on the form
    Me.Print Chr$(KeyAscii);
    End Sub
    Private Sub Form_Paint()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    'Clear the form
    Me.Cls
    'call the SendKey-function
    SendKey VK_H
    SendKey VK_E
    SendKey VK_L
    SendKey VK_L
    SendKey VK_O
    End Sub
    Private Sub SendKey(bKey As Byte)
    Dim GInput(0 To 1) As GENERALINPUT
    Dim KInput As KEYBDINPUT
    KInput.wVk = bKey 'the key we're going to press
    KInput.dwFlags = 0 'press the key
    'copy the structure into the input array's buffer.
    GInput(0).dwType = INPUT_KEYBOARD ' keyboard input
    CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    'do the same as above, but for releasing the key
    KInput.wVk = bKey ' the key we're going to realease
    KInput.dwFlags = KEYEVENTF_KEYUP ' release the key
    GInput(1).dwType = INPUT_KEYBOARD ' keyboard input
    CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    'send the input now
    Call SendInput(2, GInput(0), Len(GInput(0)))
    End Sub


    The problem is why all characters received by active window
    are "hello" (lower case)?
    Because regarding to the code (constants declaration),
    the characters are received by active windows is
    "HELLO" (upper case).
    It seems SendInput API changes all characters to lower case.
    Anyone could help?
    Thanks in advance.









  2. #2
    Bob Butler Guest

    Re: Problem in simulate keyboard event

    "Dasensa Esente" <dasensa@softhome.net> wrote in message
    news:3cfddbb0$1@10.1.10.29
    <cut>
    > It seems SendInput API changes all characters to lower case.
    > Anyone could help?


    It isn't changing it... when you press just the H key on the keyboard you
    will get an h displayed unless you have first pressed the SHIFT key. You
    need to send KeyDown Shift, KeyDown <letter>, KeyUp <letter>, <other
    letters>, KeyUp SHIFT




  3. #3
    Guest

    Re: Problem in simulate keyboard event


    "Bob Butler" <butlerbob@earthlink.net> wrote:
    >"Dasensa Esente" <dasensa@softhome.net> wrote in message
    >news:3cfddbb0$1@10.1.10.29
    ><cut>
    >> It seems SendInput API changes all characters to lower case.
    >> Anyone could help?

    >
    >It isn't changing it... when you press just the H key on the keyboard you
    >will get an h displayed unless you have first pressed the SHIFT key. You
    >need to send KeyDown Shift, KeyDown <letter>, KeyUp <letter>, <other
    >letters>, KeyUp SHIFT
    >
    >
    >


    Bob, you're right.
    Now I get what I want.
    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center