Sunday, 6 March 2011

Simulate Keystokes

From time to time it is often require to perform an operation for the user.  For example, I wanted to exit notes, which I know you can do in other ways, like from the Workspace class, but it was not working in this situation.

First in the declarations section, you must include the following line.

' This code is from a posting on Notes.Net.  Here's an explanation:
'        bVk = byte holding the hexcode of the virtual key (Alt, Control, etc)
'        bScan = (not used here)
'        dwFlags = 0 for keyDown; 2 for keyUp
'        dwExtraInfo = (not used here)

Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer,Byval dwExtraInfo As Integer)

Then in your code, you add something like this...

keybd_event &h12,0,0,0   ' <Alt> key down - to access the menu bar
keybd_event &h46,0,0,0   ' <F> key down - for FIle
keybd_event &h46,0,2,0   ' <F> key up
keybd_event &h12,0,2,0   ' <Alt> key up
keybd_event &h4C,0,0,0   ' <L> key down - for Close all tabs
keybd_event &h4C,0,2,0   ' <L> key up

No comments:

Post a Comment