View member feedback to this tip.
This code snippet demonstrates using the Windows API to perform Edit->Select All and Edit->Deselect All actions from the Notes edit menu. You can change the arguments being passed to the subroutine keybd_event to simulate other keyboard actions.
Place in declarations:
Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer, Byval dwExtraInfo As Integer)
Place in shared action or wherever desired:
Dim workspace As New NotesUIWorkspace
'select all documents
keybd_event 18,0,0,0 ' Alt key down
keybd_event Asc("E"),0,0,0 ' E key down --
invokes file menu
keybd_event Asc("A"),0,0,0 ' A key down -
Select All
keybd_event Asc("A"),0,2,0 ' A key up
keybd_event Asc("E"),0,2,0 'E key up
keybd_event 18,0,2,0 ' Alt key up
'deselect all documents
keybd_event 18,0,0,0 ' Alt key down
keybd_event Asc("E"),0,0,0 ' E key down
keybd_event Asc("E"),0,2,0 ' E key up
keybd_event 18,0,2,0 ' Alt key up
keybd_event Asc("D"),0,0,0 ' D key down
keybd_event Asc("D"),0,2,0 ' D key up
Call workspace.ViewRefresh
For example, the following snippet of
code would invoke the open database dialog:
keybd_event 18,0,0,0 '
Alt key down
keybd_event Asc
("F"),0,0,0 ' F key down -- invokes
edit menu
keybd_event Asc
("D"),0,0,0 ' D key down - Database
menu
keybd_event Asc
("O"),0,0,0 ' O key down - open
database dialog
keybd_event 18,0,
0,0 ' Alt key down
keybd_event Asc("F"),
0,2,0 ' F key down -- invokes
edit menu
keybd_event Asc("D"),
0,2,0 ' D key down - Database
menu
keybd_event Asc("O"),0,
2,0 ' O key down - open
database dialog
keybd_event 18,0,2,0 '
Alt key up
Users must be careful, however; if the last line of code, to lift up the Alt key, is not included, the keyboard will continue to function as if the Alt key is being held down.
This method doesn't work with different Notes client languages. The sequence of keys is different.
-- Anonymous
*******************************
Great workaround for SendKeys(). I just want to know, if Andrew Young can do this in a few lines of code why can't Lotus make SendKeys() work in the Notes client? Good work, Andrew.
-- Dale F.
*******************************
The tip is good, but it's not NLS portable. The Windows key events are dependent on the NLS version of the Notes client.
-- Jesus M.
*******************************
The Select All code could be minimized a little more by bypassing the Edit menu, and using CTRL+A instead. No big difference, but a few less lines.
'select all documents
keybd_event 17, 0, 0, 0 ' CTRL key down
keybd_event Asc("A"), 0, 0, 0 ' A key down (Select All)
keybd_event Asc("A"), 0, 2, 0 ' A key up
keybd_event 17, 0, 2, 0 ' CTRL key up
Unfortunately, Notes does not have a Deselect all key.-- Anonymous
*******************************
It does not work if you open another window after "deselect all" [e.g., UIWorkspace.ComposeDocument(...)].
-- Irina E.
*******************************
I just created a Smarticon to have a deselect icon with this code:
@Command([EditDeselectAll])Works great. Of course, this is done after doing a CTRL-A to select all.
-- Anonymous
Do you have comments on this tip? Let us know.
This was first published in July 2003