Classic Computer Magazine Archive COMPUTE! ISSUE 150 / MARCH 1993 / PAGE 52

Two keyboard magic tricks. (using Microsoft Windows)
by Clifton Karnes

Windows is a mouse-driven environment, and much of its power and ease of use comes from the mouse. But don't sell the Windows keyboard short. When it comes to speed, you simply can't beat keyboard commands, especially if your hands are on the keyboard already. As you probably know, Windows has a fair number of keyboard shortcuts built in, but there's plenty of room for more, and that's this column's topic.

First, much of Windows' interface is standard across applications. Most windows have a title bar, menu bar, and scroll bars (if they're needed), and the windows themselves can be moved and resized. You'll also note that almost every menu bar includes entries for File and Help. Digging deeper, if you examine almost any File menu, you'll see entries for New, Open, Close, Save, Print, and Exit. This structure is all part of Windows' standard interface, and it's one of the reasons that Windows is so easy to use--the parts of different applications that work the same way have the same menu choices.

If you look at the keyboard shortcuts in several different File menus, however, you'll see a variety of key combinations. The Save command, for example, may be Shift-F12 in one application, F2 in another, Ctrl-S in a third, and many programs will have no shortcut key at all. Unlike menu options, shortcut keys are not standard.

You can change all that, however, with Windows' Recorder.

Let's say that you want Shift-F12 to save the current file in all your Windows applications. I use Shift-F12 because it's the shortcut in Word for Windows and I've grown accustomed to it, but you can substitute any key combination you'd like.

To get started, run any Windows program that can save files, and fire up Recorder. To make sure Recorder is not recording mouse movements, go into Options, Preferences and select Ignore Mouse. Next, name your macro Save (or something similar) and choose Shift-F12 for the key combination. Now, choose Macro, Record and press Alt-F, S in your application. Alt-F activates the file menu, and S selects the Save command. Stop recording and, under Options, Properties, select Playback to Any Application. Now, Shift-F12 will save the current file in any Windows program that follows the minimum Windows standards.

You can probably think of other Windows shortcut keys that might be worth implementing. Open, Save All, and Close are possibilities.

The second keyboard shortcut I'm going to discuss involves running DOS under Windows. One of Windows' most famous shortcut keys is Alt-F4, which closes the active window. This is a quick way to exit any Windows app. Unfortunately, it won't work in a full-screen DOS session under Windows nor in a DOS box under Windows. With a little help from ANSI.SYS, however, we can create an Alt-F4 macro that will close a DOS window.

What our macro will do is simply map the strings for Ctrl-C (to end any running tasks) and the Exit command (followed by a carriage return) to the Alt-F4 key combination. It might be dawning on you that this macro will only work at the DOS prompt or when a program that Ctrl-C can exit from is running. That's true, but those instances will probably cover most of the times you need a quick DOS exit.

OK. The first thing you need to do is put ANSI.SYS in your CONFIG.SYS file, if it isn't already installed. Use the line DEVICE=ANSI.SYS or DEVICEHIGH=ANSI.SYS.

Next, we need to create an ANSI.SYS macro file that's going to look like this.


Here's a rundown on what this bizarre-looking string does. The [YLD] is the escape character. The [starts the macro. The number 107 is the Alt-F4 macro shortcut key. The number 3 represents Ctrl-C. "Exit" is, of course, Exit, and 13 is the number for a carriage return.

To create this macro, run the DOS Edit command (found in DOS 5.0 or higher) or run any editor that will let you embed an escape code in a file. To enter the escape character in DOS Edit, first press Ctrl-P, then Esc. Then, enter the remaining characters exactly as shown above and save the file.

To install this macro, you simply type it at the DOS prompt. For example, if you named this file ALT-F4.TXT, you install the macro with the following command.

The easiest way to use this macro is to put the line above in your AUTOEXEC.BAT file. If ANSI.SYS is installed, and this macro is installed before you run Windows, the Alt-F4 key combination will be available in any DOS session run under Windows.

To test this macro, exit Windows (if Windows is running), type alt-f4.txt at the DOS prompt, and rerun Windows.

Now, run DOS Prompt, either in a window or full screen; when you press Alt-F4, you'll exit--fast.