IDL

DEFINE_KEY

DEFINE_KEY

The DEFINE_KEY procedure programs the keyboard function Key with the string Value, or with one of the actions specified by the available keywords.

Note: DEFINE_KEY is intended for use with IDL’s command-line mode on Unix, and is not compatible with the IDL Workbench or with the command-line on Windows.

Examples


Defining New Function Keys

Under UNIX, IDL can handle arbitrary function keys. When adding a definition for a function key that is not built into IDL’s default list of recognized keys, you must use the ESCAPE keyword to specify the escape sequence it sends. For example, to add a function key named “HELP” which sends the escape sequence <Escape>[28~, use the command:

DEFINE_KEY, 'HELP', ESCAPE = '\033[28~'

This command adds the HELP key to the list of keys understood by IDL. Since only the key name and escape sequence were specified, pressing the HELP key will do nothing. The Value argument, or one of the keywords provided to specify command line editing functions, could have been included in the above statement to program it with an action.

Once a key is defined using the ESCAPE keyword, it is contained in the internal list of function keys. It can then be subsequently redefined without specifying the escape sequence.

It is convenient to include commonly used key definitions in a startup file, so that they will always be available.

IDL is preloaded with definitions for most widely used function keys and their escape sequences, so it is generally not necessary to specify the ESCAPE keyword. For example, to program key “F2” to redraw the current line:

DEFINE_KEY, 'F2', /REDRAW

The CONTROL keyword alters the action that IDL takes when it sees the specified characters defining the control keys. IDL may not be able to alter the behavior of some control characters. For example, CTRL+S and CTRL+Q are usually reserved by the operating system for flow control. Similarly, CTRL+Z is usually the UNIX suspend character.

Example

CTRL+D is the UNIX end-of-file character. It is a common UNIX convention (followed by IDL) for programs to quit upon encountering CTRL+D. However, CTRL+D is also used by some text editors to delete characters. To disable IDL default handling of CTRL+D, type the following:

DEFINE_KEY, /CONTROL, '^D'

To print a reminder of how to exit IDL properly, type the following:

DEFINE_KEY, /CONTROL, '^D', "print, 'Enter EXIT to quit IDL'", $
/NOECHO, /TERMINATE

To use CTRL+D to delete characters, type the following:

DEFINE_KEY, /CONTROL, '^D', /DELETE_CURRENT

Syntax


DEFINE_KEY, Key [, Value]

[, /BACK_CHARACTER] [, /BACK_WORD] [, /CONTROL |, /ESCAPE] [, /DELETE_CHARACTER] [, /DELETE_CURRENT] [, /DELETE_EOL] [, /DELETE_LINE] [, /DELETE_WORD] [, /END_OF_FILE] [, /END_OF_LINE] [, /ENTER_LINE] [, /FORWARD_CHARACTER] [, /FORWARD_WORD] [, /INSERT_OVERSTRIKE_TOGGLE] [, /MATCH_PREVIOUS] [, /NEXT_LINE] [, /NOECHO] [, /PREVIOUS_LINE] [, /RECALL] [, /REDRAW] [, /START_OF_LINE] [, /TERMINATE]

Arguments


Key

A scalar string containing the name of a function key to be programmed. IDL maintains an internal list of function key names and the escape sequences they send. Different keys are available for mapping in command-line and graphical modes, as described below.

Under UNIX, DEFINE_KEY allows you to set the values of two distinctly different types of keys:

  • Control characters: Any of the 26 control characters (CTRL+A through Ctrl+Z) can be associated with specific actions by specifying the CONTROL keyword. Control characters are the unprintable ASCII characters at the beginning of the ASCII character set. They are usually entered by holding down the Control key while the corresponding letter key is pressed.
  • Function keys: Most terminals (and terminal emulators) send escape sequences when a function key is pressed. An escape sequence is a sequence of characters starting the ASCII Escape character. Escape sequences follow strict rules that allow applications such as IDL to determine when the sequence is complete. For instance, the left arrow key on most machines sends the sequence <ESC>[D. The available function keys and the escape sequences they send vary from keyboard to keyboard; IDL cannot be built to recognize all of the different keyboards in existence. The ESCAPE keyword allows you to program IDL with the escape sequences for your keyboard. When you press the function key, IDL will recognize the sequence and take the appropriate action.

If Key is not already on IDL’s internal list, you must use the ESCAPE keyword to specify the escape sequence, otherwise, Key alone will suffice. The available function keys and the escape sequences they send vary from keyboard to keyboard; IDL’s internal list already contains definitions for most keys. The following table describes the standard key definitions.

 

Standard Key Definitions for UNIX

Editing Key

Function

Ctrl+A

Move cursor to start of line

Ctrl+B

Move cursor left one word

Ctrl+D

EOF if current line is empty, EOL otherwise

Ctrl+E

Move to end of line

Ctrl+F

Move cursor right one word

Ctrl+K

Erase from the cursor to the end of the line

Ctrl+N

Move back one line in the recall buffer

Ctrl+R

Retype current line

Ctrl+U

Delete from current position to start of line

Ctrl+W

Delete previous word

Ctrl+X

Delete current character

Backspace, Delete

Delete previous character

ESC-I

Overstrike/insert toggle

ESC-Delete

Delete previous word

Up Arrow

Move back one line in the recall buffer

Down Arrow

Move forward one line in the recall buffer

Left Arrow

Move left one character

Right Arrow

Move right one character

R13

Move cursor left one word (Sun keyboards)

R15

Move cursor right one word (Sun keyboards)

^text

Recall the first line containing text. If text is blank, recall the previous line

Other Characters

Insert character at the current cursor position

Value

The scalar string that will be printed (as if it had been typed manually at the keyboard) when Key is pressed. If Value is not present, and no function is specified for the key with one of the keywords, the key is cleared so that nothing happens when it is pressed.

Keywords


BACK_CHARACTER

Set this keyword to program Key to move the current cursor position left one character.

BACK_WORD

Set this keyword to program Key to move the current cursor position left one word.

CONTROL

Set this keyword to indicate that Key is the name of a control key. The default is for Key to define a function key escape sequence. To view the names used by IDL for the control keys, type the following at the Command Line:

HELP, /ALL_KEYS

Note: The CONTROL and ESCAPE keywords are mutually exclusive and cannot be specified together.

DELETE_CHARACTER

Set this keyword to program Key to delete the character to the left of the cursor.

DELETE_CURRENT

Set this keyword to program Key to delete the character directly underneath the cursor.

DELETE_EOL

Set this keyword to program Key to delete from the cursor position to the end of the line.

DELETE_LINE

Set this keyword to program Key to delete all characters to the left of the cursor.

DELETE_WORD

Set this keyword to programs Key to delete the word to the left of the cursor.

END_OF_LINE

Set this keyword to program Key to move the cursor to the end of the line.

END_OF_FILE

Set this keyword to program Key to exit IDL if the current line is empty, and to end the current input line if the current line is not empty.

ENTER_LINE

Set this keyword to program Key to enter the current line (i.e., the action normally performed by the “Return” key).

ESCAPE

A scalar string that specifies the escape sequence that corresponds to Key.

Note: The CONTROL and ESCAPE keywords are mutually exclusive and cannot be specified together.

FORWARD_CHARACTER

Set this keyword to program Key to move the current cursor position right one character.

FORWARD_WORD

Set this keyword to program Key to move the current cursor position right one word.

INSERT_OVERSTRIKE_TOGGLE

Set this keyword to program Key to toggle between “insert” and “overstrike” mode. When characters are typed into the middle of a line, insert mode causes the trailing characters to be moved to the right to make room for the new ones. Overstrike mode causes the new characters to overwrite the existing ones.

MATCH_PREVIOUS

Set this keyword to program Key to prompt the user for a string, and then search the saved command buffer for the most recently issued command that contains that string. If a match is found, the matching command becomes the current command, otherwise the last command entered is used. Under UNIX, the default match key is the up caret “^” key when pressed in column 1.

NEXT_LINE

Set this keyword to program Key to move forward one command in the saved command buffer and make that command the current one.

NOECHO

Set this keyword to enter the Value assigned to Key when pressed, without echoing the string to the screen. This feature is useful for defining keys that perform such actions as erasing the screen. If NOECHO is set, TERMINATE is also assumed to be set.

PREVIOUS_LINE

Set this keyword to program Key to move back one command in the saved command buffer and make that command the current one.

RECALL

Set this keyword to program Key to prompt the user for a command number. The saved command corresponding to the entered number becomes the current command. In order to view the currently saved commands and the number currently associated with each, enter the IDL command:

HELP, /RECALL COMMANDS

Example

The RECALL operation remembers the last command number entered, and if the user simply presses return, it recalls the command currently associated with that saved number. Since the number associated with a given command increases by one each time a new command is saved, this feature can be used to quickly replay a sequence of commands.

IDL> PRINT, 1
1
IDL> PRINT, 2
2
IDL> HELP, /RECALL_COMMANDS
Recall buffer length: 20
1               PRINT, 2
2               PRINT, 1

User presses key tied to RECALL.

IDL>

Line 2 is requested.

Recall Line #: 2

Saved command 2 is recalled.

IDL> PRINT, 1 
1

User presses return.

Recall Line #: 

Saved command 2 is recalled again.

IDL> PRINT, 2
2

REDRAW

Set this keyword to program Key to retype the current line.

START_OF_LINE

Set this keyword to program Key to move the cursor to the start of the line.

TERMINATE

If this keyword is set, and Value is present, pressing Key terminates the current input operation after its assigned value is entered. Essentially, an implicit carriage return is added to the end of Value.

Version History


Original

Introduced

8.2

Add note: Only works on Unix command-line.

See Also


GET_KBRD



Notes


This page has no user notes yet. Be the first one!


This information is not subject to the controls of the International Traffic in Arms Regulations (ITAR) or the Export Administration Regulations (EAR). However, it may be restricted from transfer to various embargoed countries under U.S. laws and regulations.
© 2014 Exelis Visual Information Solutions