Keyboard Primitives | |
Macros | |
assign_to_key | Assign command to key or key sequence. |
copy_keyboard | Copy a keyboard. |
get_mouse_pos | Retrieve last mouse action. |
input_mode | Effect of certain system keys. |
inq_assignment | Get key assignment for function. |
inq_kbd_char | Peek at the keyboard. |
inq_kbd_flags | Get keyboard key flags. |
inq_kbd_name | Retrieve the assigned keyboard name. |
inq_keyboard | Retrieve the keyboard identifier. |
inq_keystroke_macro | Retrieve the current keystroke macro. |
inq_keystroke_status | Determine keystroke macro status. |
inq_local_keyboard | Retrieve local keyboard identifier. |
inq_mouse_action | Retrieve the keyboard mouse handler. |
inq_mouse_type | Retrieve the button type. |
inq_remember_buffer | Determine the keystroke buffer name. |
int_to_key | Convert an keycode to mnemonic key string. |
key_list | Retrieve keyboard bindings. |
key_to_int | Convert key name to a code. |
keyboard_flush | Flush the keyboard buffer. |
keyboard_pop | Pop a keyboard from the keyboard stack. |
keyboard_push | Push a keyboard onto the keyboard stack. |
keyboard_typeables | Assign self_insert to all typeable keys. |
load_keystroke_macro | Load a recorded macro from a file. |
pause | Pause keystroke definition. |
playback | Replay a keystroke macro. |
process | Invoke a Grief engine. |
push_back | Push back a character into the keyboard. |
read_char | Read next key from the keyboard. |
remember | Start remembering keystrokes. |
save_keystroke_macro | Save the current keystroke macro. |
set_kbd_name | Set the keyboard name. |
set_mouse_action | Set keyboard mouse handler. |
set_mouse_type | Sets the mouse type. |
undo | Undo previous edit operations. |
use_local_keyboard | Associate a keyboard with a buffer. |
int assign_to_key( [string key], [string macro] )
Assign command to key or key sequence.
The assign_to_key primitive assigns a key or key sequence to a function.
The key is defined by the string parameter key, which if omitted shall be prompted. key may be specified as either an internal key code, or may be specified by a portable abbreviation, see below.
A key is “unassigned” by assigning the function nothing to the key.
If key evaluates to more than one keystroke, this shall define a multikey sequence, that is more than one key must be pressed to execute the macro. In this case, an internal key code is assigned for the key. This internal key code is returned as the value of this macro. Multikey sequences do not time out between key presses unlike the other internal keys when there is an ambiguity.
key | String identifying the particular keystroke that is being assigned. |
macro | String containing the command to be invoked, which may optionally contain one or more space seperated integer or string arguments, to be passed upon the macro upon execution. |
Generally keys are defined using their associated mnemonic possiblity prefixed with one or modifiers enclosed within a set of “<>” brackets, examples.
The following are the set of supported modifiers
In the case of simple ASCII keys their character value can be used, for example “a”.
In addition to a mnemonic “<xxx>” or ASCII “x” syntax additional alternative forms and special characters are supported.
#xxx | Substitutes the # lead sequence of digits with the represent value. For example #123 result in the key code 123. |
^x | The ^ characters treats the following character as a control code, For example ^a, is control-a. |
\ | The \ character escapes the next character, removing any special meaning. |
When it is required to state any of the special characters “<, >, %, # or ^” these can be referenced using their escaped form, example “\\<”.
The following table details the supported key sequence encoding and suitable modifiers; all names are matched case insensitive.
For examples review current supplied macro code.
Key |
Description |
Keypad |
Shift |
Ctrl |
Alt |
Meta |
---|---|---|---|---|---|---|
ASCII |
ASCII key |
x |
x |
x |
x |
|
F1..F12 |
Function keys |
x |
x |
x |
x |
|
PgDn |
Page Down |
|||||
PgUp |
Page Up |
|||||
Left |
Cursor Left |
x |
x |
x |
x |
|
Right |
Cursor Right |
x |
x |
x |
x |
|
Up |
Cursor Up |
x |
x |
x |
x |
|
Down |
Cursor Down |
x |
x |
x |
x |
|
Tab |
||||||
Back-Tab |
Shifted Tab |
|||||
Backspace |
||||||
Back |
||||||
Del |
Delete |
|||||
Enter |
Enter/Return Key |
x |
||||
Esc |
Escape key |
|||||
Space |
Space ( ) |
|||||
Home |
Cursor Home |
x |
||||
End |
Cursor End |
x |
||||
Ins |
Insert |
x |
||||
Plus |
Plus (+) |
x |
||||
Minus |
Minus (-) |
x |
||||
Star |
Multiply (*) |
x |
||||
Divide |
Div (/) |
x |
||||
Equals |
Equal (=) |
x |
||||
Cancel |
Cancel Key |
|||||
Command |
Command Key |
|||||
Copy |
Copy Key |
|||||
Cut |
Cut Key |
|||||
Exit |
Exit Key |
|||||
Help |
Help Key |
|||||
Menu |
Menu Key |
|||||
Next |
Next Key |
|||||
Open |
Open key |
|||||
Paste |
Paste key |
|||||
Prev |
Prev Key |
|||||
Prtsc |
Print-Screen Key |
|||||
Redo |
Redo Key |
|||||
Replace |
Replace |
|||||
Save |
Save |
|||||
Scroll |
Scroll |
|||||
Search |
Search |
|||||
Undo |
Undo |
|||||
Keypad-# |
Keypad 0..9 |
x |
x |
x |
x |
|
Grey-# |
Aliases for keypad |
|||||
Button# |
Button number # |
|||||
Button#-Up |
||||||
Button#-Double |
||||||
Button#-Motion |
||||||
Button#-Down |
||||||
Private# |
Private keys |
|||||
Mouse |
Special Mouse Event |
|||||
Wheel-Up |
Mousewheel up movement |
|||||
wheel-Down |
Mousewheel down |
|||||
Unassigned |
Default key Event |
x |
x |
x |
x |
x |
FocusIn |
Mouse focus Events |
x |
x |
x |
x |
x |
FocusOut |
x |
x |
x |
x |
x |
The special Unassigned key matches any unregistered key events, similar to register_macro REG_UNASSIGNED yet is assignable within the context of a specific keyboard.
The assign_to_key returns the key value assigned to sequence, otherwise -1 if the key sequence is invalid or the operation aborted.
n/a
int copy_keyboard( int kbdid, [string cmd ...] )
Copy a keyboard.
The copy_keyboard() primitive copies the key bindings associated with the keyboard identifier kbdid. The keyboard is either copied in its entirety or optionally the subset of key bindings associated with the specified list of commands cmd.
The primary use of this primitive is to obtain an explicit subset of a full keyboard for a specific use; for example a keyboard to be used by an popup for a special editing window. Another way of thinking, it a macro can inherit a keyboard, modify and then utilise locally without knowledge of the callers keyboard bindings.
kbdbid | Keyboard identifier. |
... | Optional list of command names whose key assignments should be duplicated in the current keyboard. If no commands are given, then this just creates a duplicate keyboard. |
The copy_keyboard() primitive returns the Keyboard identifier of the new keyboard. On error 0 is returned if the commands given are not found.
n/a
void get_mouse_pos( [int &x], [int &y], [int &winnum], [int &line], [int &col], [int &where], [int ®ion], [int &event] )
Retrieve last mouse action.
The get_mouse_pos() primitive retrieves the details of the last mouse action.
x, y | Screen coordinates. |
winnum | Optional an integer variable which shall be populated with the window identifier within which the (x, y) position falls, otherwise -1 if no window was mapped. |
line, col | Optional integer variables which shall be populated with the translated window coordinates, otherwise -1 if no window was mapped. |
where | Where the cursor is located within the window. |
region | Cursor position relative to any marked regions. |
event | Associated mouse event. |
Value |
Definition |
Definition |
---|---|---|
0 |
MOBJ_NOWHERE |
Not in any window. |
1 |
MOBJ_LEFT_EDGE |
Left bar of window. |
2 |
MOBJ_RIGHT_EDGE |
Right bar of window. |
3 |
MOBJ_TOP_EDGE |
Top line of window. |
4 |
MOBJ_BOTTOM_EDGE |
Bottom line of window. |
5 |
MOBJ_INSIDE |
Mouse inside window. |
6 |
MOBJ_TITLE |
On title. |
20 |
MOBJ_VSCROLL |
Vertical scroll area. |
21 |
MOBJ_VTHUMB |
Vertical scroll area. |
22 |
MOBJ_HSCROLL |
Horizontal scroll area. |
23 |
MOBJ_HTHUMB |
Horizontal scroll area. |
30 |
MOBJ_ZOOM |
Zoom button. |
31 |
MOBJ_CLOSE |
Close. |
32 |
MOBJ_SYSMENU |
System Menu. |
Value |
Description |
---|---|
0 |
No region selected. |
1 |
Cursor is before the region. |
2 |
Cursor is inside the region. |
3 |
Cursor is after the region. |
4 |
Cursor is to the left of a column region. |
5 |
Cursor is to the right of a column region. |
Returns the time since the previous mouse event.
n/a
int input_mode( int char, int flag )
Effect of certain system keys.
The input_mode() primitive controls the effect of certain characters when typed, setting the actions of character char to the desired state.
Normally the keyboard driver acts internal on specific characters which perform the control actions of XON/XOFF and the Job control stop; specifically Ctrl-S (0x13), Ctrl-Q (0x11) and Ctrl-Z (0x1a).
char | Integer value of the ascii character to be effected. |
flags | Boolean flag, if true enable the specified character to flow thru to GRIEF otherwise false to reset the default behaviour. |
The input_mode() primitive returns 1 if character previously enabled; zero otherwise.
n/a
string inq_assignment( int|string val, [int tokey = FALSE] )
Get key assignment for function.
The inq_assignment() primitive either retrieves the command that is assigned to the particular key val or the key sequence(s) that will invoke a specific command.
val | String denoting the key sequence to be decoded or an integer representing the internal key code. The string representation should be of the form described by assign_to_key. |
tokey | Optional boolean value, if true then val is taken as a macro name and the keys assigned to invoke this macro are returned. The key assignment returned is returned using the portable key definitions defined for assign_to_key. |
The inq_assignment() primitive returns a string containing the desired conversion.
For key sequence to command: the name of the command; OR “nothing” if no command is assigned; OR “ambiguous” if there is more than key sequence starting with the val.
a list of the valid key sequences for the command. The list elements are formatted with the following separators:
-or | Separates different ways of specifying a single key. |
-and | Separates keys in a multi-key sequence. |
-also | Separates multiple (different) key sequences. |
n/a
int inq_kbd_char()
Peek at the keyboard.
The inq_kbd_char() primitive determines whether a character is available to be retrieved from the keyboard using read_char.
This primitive only tests the internal look ahead buffer not the external terminal and/or keyboard stream.
none
The inq_kbd_char() primitive returns non-zero if one or more characters are available, otherwise 0 if the keyboard buffer is empty.
n/a
int inq_kbd_flags()
Get keyboard key flags.
The inq_kbd_flags() primitive returns the state of the special keyboard keys.
Bit |
Definition |
---|---|
0x01 |
Right Shift |
0x02 |
Left Shift |
0x04 |
Ctrl |
0x08 |
Alt |
0x10 |
Scroll |
0x20 |
Num Lock |
0x40 |
Caps Lock |
none
Always returns 0.
Provided only for BRIEF compatibility.
string inq_kbd_name( [int kbdid] )
Retrieve the assigned keyboard name.
The inq_kbd_name() primitive retrieves the name assigned to the keyboard kbdid using <set_kdb_name>.
kbdid | Optional integer keyboard identifier, if omitted the current keyboard shall be referenced. |
The inq_kbd_name() primitive retrieves the keyboard name otherwise an empty string is none has been assigned.
n/a
string inq_keystroke_macro( [int macroid], [int &bufnum] )
Retrieve the current keystroke macro.
The inq_keystroke_macro() primitive retrieves a string containing the definition of the current keyboard macro, which may then be saved in a file and reloaded.
The returned definition may edited and/or saved for future use; see load_keystroke_macro.
The primitive and the returned definition is a useful reference when developing customised macros.
Consult the remember source as an example how this buffer can be saved.
macroid | Optional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised. |
bufnum | Omitted integer variable if supplied shall be populated with the associated buffer number. |
nothing
Under BRIEF this primitive behaved like the functionality available via inq_keystroke_status.
int inq_keystroke_macro( [int ¯oid] )
Determine keystroke macro status.
The inq_keystroke_macro() primitive determines whether keystroke macro record or playback is active.
macroid | Optional integer variable if supplied shall be populated with the current macro identifier. |
The inq_keystroke_macro() primitive returns greater than zero if a keystroke macro is being recorded or played back.
Under BRIEF this primitive is named inq_keystroke_macro.
int inq_local_keyboard()
Retrieve local keyboard identifier.
The inq_local_keyboard() primitive retrieves the identifier associated with current local keyboard.
none
The inq_local_keyboard() primitive returns the associated keyboard identifier, otherwise 0 if none is available.
n/a
string inq_mouse_action()
Retrieve the keyboard mouse handler.
The inq_mouse_button() primitive is reserved for future BRIEF compatibility.
The inq_mouse_action() primitive retrieves the name of the current mouse action handler. This function can be used to save the current mouse handle prior to pushing a new keyboard.
none
Returns the current mouse action.
n/a
string inq_remember_buffer( [int macroid] )
Determine the keystroke buffer name.
The inq_remember_buffer() primitive derives the buffer name associated with the keyboard macro macro.
Unlike BRIEF multiple keystroke macros can be maintained. Each remember execution shall create a buffer named KBD-MACRO-# where # is the associated keyboard macro identifier. This buffer maybe then edited and/or saved to later use.
macroid | Optional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised. |
The inq_remember_buffer() primitive returns the buffer name associated with the remember buffer.
n/a
string int_to_key( int key )
Convert an keycode to mnemonic key string.
The int_to_key() primitive generates the corresponding mnemonic representation for the specified keycode key; which can be used by assign_to_key
key | Integer keycode. |
The int_to_key() primitive returns the key mnemonic string associated with the specified keycode, for example “<Ctrl-D>”; see assign_to_key for full description of key mnemonics.
n/a
list key_list( int kbdid, [int self_inserts = 0], [int bufnum] )
Retrieve keyboard bindings.
The key_list() primitive retrieves the key bindings associated with the keyboard kbdid. The definitions are returned as a list of string pairs, the first element being the key name with the second being assigned macro.
Up to two keyboards can be specified. If bufnum is specified, then the local keyboard assigned to that buffer is used. If not specified then the local keyboard map of the current buffer is used. The returned list is a union of the set keyboards.
This primitive is designed to display a list of all valid keys currently mapped in both the current local and global keyboard maps. For an example see the key_map macro.
kbdid | Optional integer keyboard identifier. If omitted then firstly the local keyboard if available is referenced otherwise the current keyboard is referenced. |
self_inserts | Optional boolean flag when non-zero keys assigned to self_insert shall be including, otherwise they are omitted from the generated list. |
bufnum | Optional buffer identifier to source the secondary local keyboard. If omitted then the local keyboard map of the current buffer is used. |
The key_list() primitive returns a list of key binding, as a set of string pairs, the first element is the key name and second being assigned macro to that key. Otherwise on error a null list.
n/a
int key_to_int( string key, int raw )
Convert key name to a code.
The key_to_int() primitive converts a mnemonic key string to an integer.
The following scheme is utilised for encoding internal key-codes, allowing for simple conversion of ASCII character code to the internal codes and vice-versa.
Firstly key-codes are divided into several ranges.
Key Code |
Range |
Description |
---|---|---|
RANGE_CHARACTER |
0x0 ... 1fffff |
Character ASCII/Unicode range. |
RANGE_FUNCTION |
0x02000... |
Function keys. |
RANGE_KEYPAD |
0x03000... |
Keypad keys. |
RANGE_MISC |
0x04000... |
Miscellaneous. |
RANGE_MULTIKEY |
0x05000... |
Multi-key stroke. |
RANGE_PRIVATE |
0x06000... |
Private key definitions for users. |
RANGE_BUTTON |
0x07000... |
Mouse buttons and movement. |
These ranges can be OR’ed with one or more of the following bits to indicate a modifier key, for example a Shift-F1 key or Ctrl-Shift-F2.
Modifier |
Code |
Description |
---|---|---|
MOD_SHIFT |
0x00200000 |
Shift’ed. |
MOD_CTRL |
0x00400000 |
Control. |
MOD_META |
0x00800000 |
Meta or Alt. |
To further simplify key handling, the follow special key manifest constants are predefined.
Key Code |
Description |
---|---|
CTRL_1 .. CTRL_10 |
Control 1 thru 10. |
ALT_1 .. ALT_10 |
Alt 1 thru 10. |
CTRL_A .. CTRL_Z |
Control A thru Z. |
ALT_Z .. ALT_Z |
Alt A thru Z. |
KEY_BACKSPACE |
Backspace. |
KEY_BREAK |
Break. |
KEY_CANCEL |
Cancel key. |
KEY_CLOSE |
Close key. |
KEY_COMMAND |
|
KEY_COPY |
Copy to clipboard. |
KEY_COPY_CMD |
|
KEY_CUT |
Cut to clipboard. |
KEY_CUT_CMD |
|
KEY_DEL |
Delete, rubout. |
KEY_DOWN |
Move down, down arrow. |
KEY_END |
End key. |
KEY_ENTER |
Enter key. |
KEY_ESC |
Escape. |
KEY_EXIT |
|
KEY_HELP |
Help, usage. |
KEY_HOME |
Home key. |
KEY_INS |
Insert. |
KEY_LEFT |
Move left, left arrow. |
KEY_MENU |
Menu key. |
KEY_NEWLINE |
New line. |
KEY_NEXT |
Next. |
KEY_OPEN |
Open key. |
KEY_PAGEDOWN |
Page down. |
KEY_PAGEUP |
Page up. |
KEY_PASTE |
Paste clipboard. |
KEY_PREV |
Prior, previous. |
KEY_REDO |
Redo, again. |
KEY_REPLACE |
|
KEY_RIGHT |
Move right, right arrow. |
KEY_SAVE |
|
KEY_SEARCH |
Search. |
KEY_TAB |
Tab. |
KEY_UNDO |
Undo key. |
KEY_UNDO_CMD |
Undo key. |
KEY_UP |
Move up, up arrow. |
KEY_WDOWN |
|
KEY_WDOWN2 |
|
KEY_WLEFT |
|
KEY_WLEFT2 |
|
KEY_WRIGHT |
|
KEY_WRIGHT2 |
|
KEY_WUP |
|
KEY_WUP2 |
|
KEY_VOID |
NUL key-code. |
The key encoding are exposed only for reference and may change without notice; for example to fully support Unicode. As such its advised keys should only be referenced using their string mnemonic representation when dealing directly with key-codes, for example.
switch (keycode) {
case key_to_int("<F1>"):
f1();
break;
case key_to_int("<Ctrl-A>"):
ctrla();
break;
case key_to_int("<Ctrl-B>"):
ctrlb();
break;
:
key | String contains a single mnemonic key description, for example (“i” or “<Ctrl-z>”). |
raw | Optional boolean flag. If non-zero, then key is taken to be a raw key stroke/escape sequence, as entered by a function key on the keyboard. In this case, the key-code assigned to that key is returned. |
The key_to_int() primitive returns an integer representing the internal key code assigned to the specified key sequence, or -1 if the sequence does not correspond to an valid key.
n/a
void keyboard_pop( [int save = FALSE] )
Pop a keyboard from the keyboard stack.
The keyboard_pop() primitive removes the top keyboard, from the last-in/first-out (LIFO) keyboard stack.
Each invocation of keyboard_push must have a corresponding invocation of keyboard_pop.
The keyboard resource and associated identifier shall only remain valid if the save argument is non-zero, otherwise the keyboard definition is deleted and its memory reclaimed.
If the current buffer is the same as it was when the keyboard was pushed, the current local keyboard is also restored to its former value.
save | Optional boolean value, if specified as true the keyboard resource is retained otherwise if false or omitted it is discarded. |
nothing
n/a
void keyboard_push( [int kbdid] )
Push a keyboard onto the keyboard stack.
The keyboard_push() primitive pushes a keyboard, either an existing or new, onto the last-in/first-out (LIFO) keyboard stack. Being a stack each invocation of keyboard_push must have a corresponding invocation of keyboard_push; otherwise the keyboard objects shall never to released, resulting in a resource/memory leak.
Either the specified keyboard kbdid or if omitted a new empty keyboard object shall be pushed onto the stack and become the current keyboard (See: inq_keyboard). When a new keyboard is created, it is empty and the current local keyboard is temporarily unassigned.
A keyboard resource is a table of key bindings, that is keys mapped against the macro which should be executed when encountered. During initialisation the default keyboard resource binds the usual editing keys, keyboard_push() permits the creation of macro specific keyboards, supporting temporarily bind macros to keys for their operation.
The default key bindings along with keyboard_typeables includes -
Key |
Macro |
---|---|
F1 |
change_window |
F2 |
move_edge |
F3 |
create_edge |
F4 |
delete_edge |
F5 |
search_fwd |
F6 |
translate |
F7 |
remember |
F8 |
playback |
F9 |
load_macro |
F10 |
execute_macro |
Shift-F7 |
pause |
Ins |
paste |
End |
end_of_line |
Down |
down |
Left |
left |
Right |
right |
Home |
beginning_of_line |
Up |
up |
Del |
delete_block |
Cut |
cut |
Copy |
copy |
Undo |
undo |
Page-Down |
page_down |
Page-Up |
page_up |
Wheel-Down |
page_down |
Wheel-Up |
page_up |
Shift-Keypad-2 |
”change_window 2”, see change_window |
Shift-Keypad-4 |
”change_window 3” |
Shift-Keypad-6 |
”change_window 1” |
Shift-Keypad-8 |
”change_window 0” |
Ctrl-Keypad-1 |
end_of_window |
Ctrl-Keypad-3 |
end_of_buffer |
Ctrl-Keypad-7 |
top_of_window |
Ctrl-Keypad-9 |
top_of_buffer |
Ctrl-X |
exit |
Alt-0 |
”drop_bookmark 0”, see drop_bookmark |
Alt-1 |
”drop_bookmark 1” |
Alt-2 |
”drop_bookmark 2” |
Alt-3 |
”drop_bookmark 3” |
Alt-4 |
”drop_bookmark 4” |
Alt-5 |
”drop_bookmark 5” |
Alt-6 |
”drop_bookmark 6” |
Alt-7 |
”drop_bookmark 7” |
Alt-8 |
”drop_bookmark 8” |
Alt-9 |
”drop_bookmark 9” |
Alt-A |
”mark 4”, see mark |
Alt-B |
<buffer_list> |
Alt-C |
”mark 2”, see mark |
Alt-D |
delete_line |
Alt-E |
edit_file |
Alt-F |
<feature> |
Alt-G |
goto_line |
Alt-I |
insert_mode |
Alt-J |
goto_bookmark |
Alt-K |
delete_to_eol |
Alt-L |
mark |
Alt-M |
mark |
Alt-O |
output_file |
Alt-P |
print |
Alt-Q |
<quote> |
Alt-R |
read_file |
Alt-S |
search_fwd |
Alt-T |
translate |
Alt-U |
undo |
Alt-V |
version |
Alt-W |
write_buffer |
Alt-X |
exit |
Alt-Z |
shell |
kbdid | Integer keyboard identifier, if omitted or zero a new keyboard is created and pushed. Keyboards within the stack are assumed to be unique; beware pushing a keyboard which already exists which shall have undefined effects. |
The keyboard_push() primitive returns the identifier of the referenced keyboard, otherwise -1 on error.
The following example creates a new keyboard with only typeable key binds active.
keyboard_pop();
keyboard_push();
keyboad_typeables();
The following example shows how to create a temporary keyboard mapping for use within a macro.
keyboard_push();
assign_to_key("<Alt-H>", "help");
// additional key bindings
::
process();
keyboard_pop();
n/a
int keyboard_typeables()
Assign self_insert to all typeable keys.
The keyboard_typeables() primitive populates the keyboard with all of the standard keys, example include ASCII keys (for example A-Z and 0-9), Backspace, Tab, and Enter are bound to self_insert.
none
nothing
n/a
int load_keystroke_macro( string def )
Load a recorded macro from a file.
The load_keystroke_macro() primitive loads the specified keystroke macro macro, being a string in a similar format returned by inq_keystroke_macro. This primitive is designed to allow user macros to load macros from external files.
macro | String containing the macro definition. |
The load_keystroke_macro() primitive returns the newly associated macro identifier, otherwise -1 on error.
n/a
void pause()
Pause keystroke definition.
The pause() primitive pauses a keyboard macro definition.
Usually all keyboard input typed during a remember sequence is saved in the keyboard macro buffer. Pressing a key assigned to pause causes the remember sequence to suspend saving the characters.
none
nothing
n/a
int playback( [int macroid] )
Replay a keystroke macro.
The playback() primitive replays the previously saved keyboard macro macro.
macroid | Optional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised. |
The playback() primitive returns greater than or equal to zero if playback was successful, otherwise less than zero on error.
n/a
void process()
Invoke a Grief engine.
The process() primitive invokes an instance of the Grief command-loop recursively by accepting keystrokes and calling the functions assigned thru the associated key bindings (See: assign_to_key).
process is usually invoked after building the required environment including buffers and/or windows with an associated keyboard. Process nesting may occur to any depth, within the bounds of Griefs maximum nesting level. The
current command loop executes until the session is terminated by an exit command.
none
nothing
n/a
void push_back( int key, [int front], [int x], [int y] )
Push back a character into the keyboard.
The push_back() primitive pushes the specified key code key into the keyboard input buffer.
The front is zero or omitted the key shall pushed to the back of the keyboard buffer, otherwise to the front.
key | Key code. |
front | Optional boolean value, which if specified and is TRUE (non-zero) then the character is pushed pushed at the front of any previous characters. Otherwise if either omitted or FALSE (zero) then the key is pushed back after all previously pushed back characters. |
x, y | Mouse position, required when pushing back mouse events. |
nothing
Mouse support is a GriefEdit extension.
void read_char( [int timeout = 0], [int mode = 0] )
Read next key from the keyboard.
The read_char() primitive attempts to retrieve the next character from the keyboard.
The timeout argument specifies the handling of non key conditions, is other words when no keys are available. If a positive value the timeout argument specifies the interval in milliseconds read_char() should block waiting for a key to become ready. If the time limit expires before any key events read_char returns -1. If omitted or zero read_char shall block unconditionally until a key is available. A negative (-1) timeout shall not block returning immediately effectively polling the keyboard.
The mode parameter controls the type of keyboard event to be returned. Supported modes are as follows.
Mode |
Description |
---|---|
0 |
Normal. |
>0 |
Raw mode. |
<0 |
Extended, returning additional keys codes including mouse. |
timeout | Optional timeout in milliseconds, if omitted or zero read_char blocks until a key-code is available, otherwise -1 shall simply poll for the next key. |
mode | Optional request mode, see above. |
The read_char() primitive returns the key-code, otherwise -1 on a timeout.
Use of a ‘-’1 timeout value is required to emulate BRIEF.
int remember( [string|int overwrite], [int macroid] )
Start remembering keystrokes.
The remember() primitive control macro recording, starts remembering keystrokes, which can be later replayed with the playback function.
Recording is stopped by a second call to the remember macro.
The remember() primitive is not usually called as part of a macro but is usually bound to a keyboard key, for example (<F7>).
Unlike BRIEF multiple keystroke macros can be maintained. Each remember execution shall create a buffer named KBD-MACRO-# where # is the associated keyboard macro identifier. This buffer maybe then edited and/or saved for later use. The inq_remember_buffer primitive shall derive the buffer name.
Only the macros directly executed by the user are saved within the macro. In other words top level macros, for example the resulting dialog, shall not be reported.
The pause primitive temporarily stops recording the current keystroke sequence; by default assigned to (<Shift+F7>). This feature is useful if part of the keystroke macro being remembered is different each time the macro is played back. Before the variable part of the macro, press Shift+F7. Perform the variable part and press Shift+F7 to resume recording.
When the macro is played back, it will pause at the point Shift+F7 was pressed to allow the user to perform the variable portion of the sequence. Pressing Shift+F7 then resumes playback.
overwrite | Optional string containing whether or not the current macro should be overwritten. If either a case insensitive string contained “y[es]” or a non-zero the macro shall be overwritten. If omitted the user shall be prompted. |
macroid | Optional integer macro identifier specifies the keyboard against which to store the keystrokes, if omitted the next free keyboard identifier is utilised. |
The remember() primitive returns the positive identifier assigned to the keystroke macro on completion, 0 if the remember was cancelled, otherwise -1 on error or the recording began.
n/a
int save_keystroke_macro( string filename )
Save the current keystroke macro.
The save_keystroke_macro() primitive saves the current remembered keystrokes macro to the specified file filename.
filename | String containing the name of the destination file to which the keystroke macro is to be saved. If no file extension is stated, the extension .km shall be used. |
The save_keystroke_macro() primitive returns greater than zero on success, otherwise -1 on error.
void set_kbd_name( string name, [int kbdid] )
Set the keyboard name.
The set_kbd_name() primitive assigned the label name as the name of the keyboard kbdid, allowing primitives to assign a descriptive or meaningful definition to a keyboard. These names or descriptions may then be utilised by macros.
name | String containing the name to be assigned. If empty the current name shall be cleared. |
kbdid | Optional integer keyboard identifier, if omitted the current keyboard shall be referenced. |
nothing
n/a
int set_mouse_action( string mouse_handler )
Set keyboard mouse handler.
The set_mouse_button() primitive is reserved for future BRIEF compatibility.
The set_mouse_action() primitive sets the function mouse_handler as the mouse action handler within the current keyboard.
void
mouse_handler(
int event, // event code; see below
int modifier, // modifier keys
int parm2, // either line or scrollbar position
int parm3 // either column or thumb position
)
{
switch(event) {
case BTN1_MOVE:
break;
case BTN2_MOVE:
break;
case BTN3_MOVE:
break;
case BTN1_DOWN:
break;
case BTN2_DOWN:
break;
case BTN3_DOWN:
break;
case BTN1_UP:
break;
case BTN2_UP:
break;
case BTN3_UP:
break;
case BTN1_CLICK:
break;
case BTN2_CLICK:
break;
case BTN3_CLICK:
break;
case BTN1_DBLCLK:
break;
case BTN2_DBLCLK:
break;
case BTN3_DBLCLK:
break;
}
}
mouse_handler | A string containing the name of the function to be associated with the current keyboard. |
Returns the previous mouse action.
n/a
int set_mouse_type()
Sets the mouse type.
The set_mouse_type() primitive sets the mouse type.
type | Integer stating the current mouse type. |
button1 | Option integer indicates which button shall be treated as the first button. A value of zero indicates the left-most, with a value of one indicates the right-most button. By default the left-most button is the mouse button one. |
none
n/a
int undo( [int move], [int pastwrite = -1], [int redo = FALSE] )
Undo previous edit operations.
The undo() primitive undoes buffer modifications on the current buffer.
Executing without arguments undoes the last operation performed on the buffer, including cursor movement, any text modification and marked region modification. If the previous operation on the buffer was a macro, or a complex operation, e.g. global translate, then all the buffer modifications performed are undone in one step.
The move option limits the undo operation to the last buffer modification, restoring the cursor to the its location where the buffer was actually modified.
Each buffer maintains their own undo stack, unless disabled (See: set_buffer_flags). Under BRIEF the undo stack for a particular buffer was cleared when the buffer is written to disk, as such it was not possible to undo any operations performed on the buffer before the last write_buffer.
Under GriefEdit the undo stack is retained for the duration of the editor lifetime. If pastwrite is specified as positive value, the undo shall perform undo’s beyond the last write_buffer; by default the user is prompted as follows
Undo past saved file mark?
Unlike BRIEF, it is possible to call undo from within a macro, but this use is highly dubious. It is normally called by the user directly from one of the key assignments.
move | Optional boolean value, if true then all buffer operations up the last buffer modification are undone. |
pastwrite | Option integer stating the write_buffer undo logic. Zero (0) disables undo’s past the last write, a negative value (-1) prompts the user whether to continue otherwise and a postive value (1) permits undo’s without prompt. |
redo | Optional boolean value, if true the previous undo action shall be undone. |
The undo() primitive returns the number of operations undo; this is GriefEdit extension.
n/a
int use_local_keyboard( int kbdid )
Associate a keyboard with a buffer.
The use_local_keyboard() primitive cause the current keyboard to be associated with the current buffer.
kbdid | Keyboard identifier. |
The use_local_keyboard primitive return 0 on success otherwise -1 on error.
n/a
inq_local_keyboard, keyboard_pop, keyboard_push
$Id: $
To send feedback on this topic email: grie@gmai l.com fedit
Copyright © Adam Young All Rights Reserved.
Assign command to key or key sequence.
int assign_to_key( [string key], [string macro] )
Copy a keyboard.
int copy_keyboard( int kbdid, [string cmd ...] )
Retrieve last mouse action.
void get_mouse_pos( [int &x], [int &y], [int &winnum], [int &line], [int &col], [int &where], [int ®ion], [int &event] )
Effect of certain system keys.
int input_mode( int char, int flag )
Get key assignment for function.
string inq_assignment( int|string val, [int tokey = FALSE] )
Peek at the keyboard.
int inq_kbd_char()
Get keyboard key flags.
int inq_kbd_flags()
Retrieve the assigned keyboard name.
string inq_kbd_name( [int kbdid] )
Retrieve the keyboard identifier.
int inq_keyboard()
Retrieve the current keystroke macro.
string inq_keystroke_macro( [int macroid], [int &bufnum] )
Determine keystroke macro status.
int inq_keystroke_macro( [int ¯oid] )
Retrieve local keyboard identifier.
int inq_local_keyboard()
Retrieve the keyboard mouse handler.
string inq_mouse_action()
Retrieve the button type.
int inq_mouse_type()
Determine the keystroke buffer name.
string inq_remember_buffer( [int macroid] )
Convert an keycode to mnemonic key string.
string int_to_key( int key )
Retrieve keyboard bindings.
list key_list( int kbdid, [int self_inserts = 0], [int bufnum] )
Convert key name to a code.
int key_to_int( string key, int raw )
Flush the keyboard buffer.
void keyboard_flush()
Pop a keyboard from the keyboard stack.
void keyboard_pop( [int save = FALSE] )
Push a keyboard onto the keyboard stack.
void keyboard_push( [int kbdid] )
Assign self_insert to all typeable keys.
int keyboard_typeables()
Load a recorded macro from a file.
int load_keystroke_macro( string def )
Pause keystroke definition.
void pause()
Replay a keystroke macro.
int playback( [int macroid] )
Invoke a Grief engine.
void process()
Push back a character into the keyboard.
void push_back( int key, [int front], [int x], [int y] )
Read next key from the keyboard.
void read_char( [int timeout = 0], [int mode = 0] )
Start remembering keystrokes.
int remember( [string|int overwrite], [int macroid] )
Save the current keystroke macro.
int save_keystroke_macro( string filename )
Set the keyboard name.
void set_kbd_name( string name, [int kbdid] )
Set keyboard mouse handler.
int set_mouse_action( string mouse_handler )
Sets the mouse type.
int set_mouse_type()
Undo previous edit operations.
int undo( [int move], [int pastwrite = -1], [int redo = FALSE] )
Associate a keyboard with a buffer.
int use_local_keyboard( int kbdid )
Noop.
void nothing()
Register a callback procedure.
int register_macro( int type, string macro, [int local = FALSE] )
Process mouse event.
void process_mouse( [int b1], [int b2], [int b3], int x, int y )
Convert window coordinates.
int translate_pos( int x, int y, [int &winnum], [int &line], [int &col] )
Insert a character as if it was typed.
void self_insert( [int character] )
Selects a new window.
void change_window( [int direction], [string message] )
Modify a window.
int move_edge( [int direction], [int amount] )
Create an edge, splitting the window.
int create_edge( [int direction] )
Delete an edge, combining a split window.
int delete_edge( [int direction] )
Buffer search.
int search_fwd( string pattern, [int re], [int case], [int block], [int length] )
Buffer search and replace.
int translate( string pattern, string replacement, [int global], [int re], [int case], [int block], [int forward] )
Load a macro object.
int load_macro( string filename, [int reload = 1] )
Invokes a command by name.
declare execute_macro( [string cmd], ... )
Insert scrap buffer at cursor location.
int paste( [int syspaste = FALSE] )
Goto end of line.
int end_of_line()
Move position down one line.
int down( [int lines = 1] )
Move position left one charcter.
int left( [int columns = 1], [int wrap = TRUE] )
Move position right one character.
int right( [int columns = 1], [int wrap = TRUE] )
Goto beginning of line.
int beginning_of_line()
Move position up one line.
int up( [int lines = 1] )
Deleted selected region.
int delete_block()
Cut marked area to scrap.
int cut( [int append = FALSE], [int syscopy = FALSE] )
Copy marked area to scrap.
int copy( [int append = FALSE], [int keep = FALSE] )
Move position down a page.
int page_down( [int pages = 1] )
Move position up a page.
int page_up( [int pages = 1] )
Goto end of the current window.
int end_of_window()
Move cursor to end of current buffer.
int end_of_buffer()
Goto top of the current window.
int top_of_window()
Move cursor to start of current buffer.
int top_of_buffer()
Exit current process level.
void exit( [string y_or_w] )
Create or update a bookmark.
int drop_bookmark( [int bookid], [string yesno], [int bufnum], [int line], [int column], [int local = FALSE] )
Toggle the anchor status.
int mark( [int type = MK_NORMAL] )
Delete current line.
void delete_line()
Edit a file.
int edit_file( ... )
Move to a particular line.
int goto_line( [int lineno] )
Set the buffer insert/overstrike mode.
int insert_mode( [int value], [int bufnum] )
Seek a bookmark.
int goto_bookmark( int bookid = NULL, [int &bufnum], [int &line], [int &column] )
Delete to end-of-line.
void delete_to_eol()
Change the output file-name.
int output_file( [string filename] )
Print formatted string to stdout.
int print()
Read into the current buffer.
int read_file( [string filename], [int glob = TRUE], [string encoding = NULL] )
Version information.
int version( [int major | string machtype], [int min], [int edit], [int release], [string machtype], [string compile], [int cmversion], [string features], [string build] )
Write to buffer content.
int write_buffer( [string filename], [int flags], [string encoding] )
Spawn a sub-shell process.
int shell( [string cmd], [int use_shell], [string completion], [string stdin], [string stdout], [string stderr], [int mode], [string spec] )
Suspend current process.
void suspend()
Set buffer flags.
void set_buffer_flags( [int bufnum], [string|int or_mask], [string|int and_mask], [int set = 1] )
Redo an undo operation.
void redo()