Keysend.bas

=================== Developer Notes ==============

IMPORTANT

The Sendkey sub sends keydown and keyup events to the keyboard buffer separately. If you set a break point after a keydown for the Alt, Ctrl or Shift keys or step through the code to such a point, your VB will become unusable and you will have to reboot to clear the keyboard buffer.


The public sub Sendkey is a direct replacement for the VB Sendkeys. To use it, all you have to do is add this module to your project then replace "Sendkeys" with "Sendkey" in your code. Sendkey interprets all Sendkeys parameters without modification. DOT.NET NOTE: If your code uses VB6.SendKeys, This is a simple case of find and replace. If it uses Sendkeys.Send / Sendkeys.SendWait then you need to retype it in the form Sendkey (String,Wait)

Sendkey is designed for Windows versions, NT, 2000, XP and beyond. It is not fully compatible with Windows 9x and ME. In 9x and Me, Sendkey cannot send printable characters who's ASCII value is greater than 127. (â,ä,à Etc.).

You can still use Sendkey as a universal replacement because, if it detects 9x, it passes your parameters to the VB Sendkeys and exits. The lines which redirect to Sendkeys are clearly marked at the start of the Sendkey sub. You can rem these to use the additional keys in Sendkey with 9x and ME if you wish but see "To rem or not to rem" below.

Differences between Sendkey and Sendkeys.

1. In the VB Sendkeys, setting Wait to true causes the sub not to return before the keystrokes have been processed. In Sendkey, setting Wait to true allows a fixed time for the keystrokes to be processed. As supplied, this is set to 20Ms. We have found this to be good for most jobs. If you wish, you can change this in the line: If Wait <> 0 Then WaitTime (20)
near the end of the Sendkey sub.

2. In Sendkey, you can specify numbers from the numberpad. Use {NUMPAD0} to {NUMPAD9}. You can also specify the PrtScr key. Send {PRTSCR} to send the entire screen to the clipboard or %{PRTSCR} to send the active window to the clipboard.

3. In the VB Sendkeys, you cannot set the state of the toggle keys, Capslock, Numlock and Scrollock. They are always reset to their original condition. In Sendkey, this is also the default behavior but you can also set them.

This is how it works:

The sub starts by noting the position of the toggle keys and turning off any that are on. It ends by resetting them to their original conditions.

Notice that the Wait parameter in Sendkey is integer, not boolean. You can set it to a number as well as true or false. To inhibit resetting the toggle keys, set wait to a number.

If the number contains the digit "2", Capslock is not reset.
If the number contains the digit "3", Numlock is not reset.
If the number contains the digit "4", Scrollock is not reset.

Examples:

Sendkey {CAPSLOCK},2 sets Capslock on.
Sendkey {CAPSLOCK 2},2 sets Capslock off
Sendkey (CAPSLOCK}{SCROLLLOCK},24 sets Capslock and Scrollock on

TO REM OR NOT TO REM
=====================
If you rem the redirect to Sendkeys for 9x/ME, you can use the Sendkey extra keys {PRTSCR}, {NUMPAD0}, and the ability to set the toggle keys in 9x/ME, but you cannot send characters with ASCII over 127.

If you don't rem the redirects, Sendkey is good for all Sendkeys parameters on all platforms, but if you use the extra keys, {PRTSCR} and {NUMPAD0) to {NUMPAD9}, they will fail without error on 9x/ME.
=== ==================

YOUR COPYRIGHTS AND OURS

The file Keysend.bas is copyright M8 Software 2006. You may not sell, give or reproduce it in any way save for your own backup copies. You may only use it on as many development machines as you have purchased licenses for.

The native or Pcode which you compile from Keysend.bas is yours to do with as you please. ==================================================================