Wednesday
Mar192003
WinAPI to mimic keystrokes
March 19, 2003
There are times when there seems to be no easy way to accomplish something programmatically - the only way to do the task at hand is via the keyboard. I recently shared this tip with someone at work, so figured I'd post it here: using the WinAPI to send keystrokes to the PC.
In this example, the API will be used to send keystrokes to deselect selected documents in a view and then refresh the view. This would be the same as manually hitting <Alt-E-D> to deselect and then hitting <F9> to refresh (there are, of course, many things you could do by sending keystrokes). The critical piece here is to know the hex code for whatever keystrokes need to be sent to the PC. There are a number of places on the web to find this. Here's a site of ASCII codes, and here's a site that includes the codes for some of the function keys. You want the hex value for the key, not the decimal value.
OK, so here's a LotusScript example. The 'magic' part of the code (the declaration of the API call) I believe I pulled from NotesNet quite a while back. And the html rendition of the code was, of course, rendered using Julian's ls2html routine.
Of course, it's your responsibility to ALWAYS carefully test anything before using it production!
In this example, the API will be used to send keystrokes to deselect selected documents in a view and then refresh the view. This would be the same as manually hitting <Alt-E-D> to deselect and then hitting <F9> to refresh (there are, of course, many things you could do by sending keystrokes). The critical piece here is to know the hex code for whatever keystrokes need to be sent to the PC. There are a number of places on the web to find this. Here's a site of ASCII codes, and here's a site that includes the codes for some of the function keys. You want the hex value for the key, not the decimal value.
OK, so here's a LotusScript example. The 'magic' part of the code (the declaration of the API call) I believe I pulled from NotesNet quite a while back. And the html rendition of the code was, of course, rendered using Julian's ls2html routine.
Of course, it's your responsibility to ALWAYS carefully test anything before using it production!
Reader Comments