Jan 15, 2012

Sending Key Press

You can make a control likely pressing (a) key(s). 
First declare the Win32 API modul on Declare > Local External Functions
Subroutine keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) Library "user32.dll"

//Next is an example to simulate pressing "A" key
integer li_vkey
li_vkey = 65 // Character A
sle_1.setfocus() // the desired control to view
keybd_event( li_vkey, 1, 0, 0)

//Another example to simulate "Backspace" key
integer li_vkey
integer li_pos
li_pos = len(sle_1.Text) + 1
sle_1.selectText(li_pos, 0)// Cursor position on last text
li_vkey = asc ("~b") // backspace
keybd_event( li_vkey, 1, 0, 0)

It 100% works.

1 comment:

  1. Hello!

    I tried the code for the CapsLock key to get it to be in position ON.

    keybd_event(20, 58, 0, 0)

    In any such call, the keypad wrote in capitals, but immediately after and for each first time, did not recognize the CapsLock key (the real button) press. :-(

    Any suggestion?

    Thanks in advance!