Keyboard

Information about the various keys on the keyboard are discussed in a section dedicated to the keyboard keys.

[#kbstufer]: Sending Keystrokes

Keyboard keys can be sent to the operating system by having a user press an actual keyboard key, but there are other ways too. Some software can be used to simulate keystrokes. This is called “keyboard keystroke buffer stuffing” (or, perhaps more commonly, “keyboard stuffing”), so a program that does this can be called something like a “keyboard stuffer”.

There is now a section just about the topic of input stuffing.

Wikipedia's page for AutoHotkey : section titled “See also” contains some references to some automation software. Here are some additional details about some specific options:

Microsoft Windows
WScript.Shell SendKeys

This is built into the operating system.

Sending Keystrokes to a Program

C:\> Copy CON sndky.js
var ciNormFc = 1; // Constant Integer: Normal Focus
var objShell;
var objError;
try {
objShell = new ActiveXObject("WScript.Shell");
}
catch (objError) {
;
}
// Start a new copy of Notepad
objShell.Run( "Notepad.exe" , ciNormFc );
WScript.Sleep( 300 );
// Send keystrokes to a copy of Notepad
objShell.AppActivate( "Untitled - Notepad" );
WScript.Sleep( 100 );
objShell.SendKeys( "Hello" );
WScript.Sleep( 100 );
objShell.SendKeys( "{ENTER}" );
WScript.Sleep( 100 );
objShell.SendKeys( "^m" );
WScript.Sleep( 100 );
objShell.SendKeys( "{TAB}" );
WScript.Sleep( 100 );
objShell.SendKeys( "World!" );

(Press Ctrl-Z to send the EOF character and, thereby, stop creating the file via copy.)

C:\> CScript sndky.js

“Key, Scriptiong Guy!” Blog: Weekend Scripter: Cheesy Script to Set Speaker Volume shows using this sort of approach with virtual key codes. This may be done by using the following line at an appropriate part of the script that was shown:

objShell.SendKeys( String.fromCharCode( 174 ) );
Keyboard remapping

At the time of this writing this has not been thoroughly tested (or even tested at all) by the author of this text. This simply documents some information that has been found.

This requires rebooting to take effect, but doesn't require third party software. (Just requires NT4 (where this was undocumented but functional), 2K (where this was first documented), XP, Vista, or 7. Or, presumably, newer.) That said, some people have recommended using third party software to generate the mappings. Once a mapping is figured out, though, this simply involves editing the registry (and rebooting). This means that you don't need to be constantly running software (like AutoHotkey, which takes up memory).

Some details may be at: SharpKeys (which discusses some capabilities and limitations), MSDN: Keyboard and mouse class drivers, ScancodeMap info, Northcode: Securing Windows For Use As A Kiosk, SuperUser: remapping Ctrl-Alt-Del

Example registry value shown by SmallVoid:

REG_BINARY
00,00,00,00,00,00,00,00,03,00,00,00,00,00,5b,e0,00,00,5c,e0,00,00,00,00

Meaning:

Each pair of digits is one byte, and this is meant to be processed in groups of four bytes.

The first two sets of four bytes are all zeros. So, the first eight pairs of digits are pairs of zeros. (Out of those eight pairs, the first half represent a “version”, and the next half is meant to represent “flags”.)

The next set of four pairs is 03,00,00,00. The first number there, 3, specifies how many “entries” will exist in the remainder of this value. Each “entry” is four bytes. The last entry is supposed to be all zeros.

That describes all of the bytes except: 00,00,5b,e0,00,00,5c,e0

00,00,5b,e0 remaps key 5b,e0 to nothing, which disables that key. Key 5b,e0 is Left Start key (which frequently has a Microsoft Windows logo on it). The 00,00,5c,e0 does a similar thing for the Right Start key (which also frequently has a Microsoft Windows logo on it).

Perhaps relevant: Scancodes, Scan Codes Demystified, MS Scan Code info (mirrored at: MS KB info from GitHub), Art of Asm Appendix C: Keyboard Scan Codes


...

On similar topic: For country codes: Window IT Pro: default keyboard layout during login. Microsoft released some software:Microsoft Keyboard Layout Creator (MSKLC).

AutoHotkey from AHKScript.org

This program also offers a lot more features. In addition to being related to being able to automate keystrokes, this program can help to automate what happens when someone presses a physical key (or a combination of physical keys).

This supports keyboard input, mouse input, and joystick input. This also works with Win9x.

After running AutoHotKey, the System tray icon can be used to edit a script. After editing the script, the same icon can be used to reload the script so that changes take immediate effect. To see what changes to make, review: AutoHotKey Remapping, AutoHotKey Joystick Remapping support

JPSoftware KeyStack

A KeyStack command built into a command prompt by JP Software. For example, the freeware TCC/LE. More information about JP Software can be found from TOOGAM's page about JP Software products. Their modern software is released from http://JPSoft.com.

Unix
X Windows
semicommplete's xdotool
...
xautomation
also supports visual scraping
Knee
Supports recording and playback of user events
Autokey
Similar to AutoHotkey (for Microsoft Windows). (Presumably also similar to AUTOKEY for DOS.)

If a solution isn't working as expected in a certain environment, using the Compiz commands plugin may help, according to SuperUser answer about handling keys.

DOS
Key-Fake
PC-Magazine released assembly source code: see keyboard stuffers.
4DOS KeyStack

Using KeyStack, built into JP Software's 4DOS (which was once shareware, but now has now had source code released, and also has versions that can be freely used). This built-in command requires uses another piece of software, such as the built-in TSR called KStack which is bundled with 4DOS distributions. However, GLKeys claims to be compatible and require less memory. (GLKeys documentation.)

StuffIt
See keyboard stuffers.
AUTOKEY (DOS .COM file)
AUTOKEY and KEYCODE for DOS

There may be more at SimTel mirror: keyboard utilities.

Using this software, it is possible to make some elaborate tasks more automated. However, there are drawbacks. Ansgar Wiechers's comment states, “Never use SendKeys for this kind of automation.” The key problem is that simply sending keystrokes can be pretty inflexible, so unexpected events can cause failures. As one example: a program might not be ready to receive keystorkes as quickly as expected, especially if a program runs slower than another time that the same program runs. Another issue could occur if a user switches programs; then keystrokes may go into a different program than what is expected. This might be particularly harmful if the keystrokes included a password. (On top of that, keystrokes are often stored in unencrypted plain text, which is another way that password usage ends up being rather insecure.) If the program's user interface changes, the keystrokes might not have the desired effect. Such changes are less likely to break things when using software that works directly with a program's internal functions instead of relying on interactions between keyboard input and a program's user interface. All in all, the technique of keyboard stuffing can work, but people who deploy such solutions should be aware of the limitations, and it would be good for them to consider whether another approach would be better.

For more discussion that may be related to keyboards, see: PS/2 ports and USB.