Keyboard Primitives

Summary
Keyboard Primitives
Macros
assign_to_keyAssign command to key or key sequence.
copy_keyboardCopy a keyboard.
get_mouse_posRetrieve last mouse action.
input_modeEffect of certain system keys.
inq_assignmentGet key assignment for function.
inq_kbd_charPeek at the keyboard.
inq_kbd_flagsGet keyboard key flags.
inq_kbd_nameRetrieve the assigned keyboard name.
inq_keyboardRetrieve the keyboard identifier.
inq_keystroke_macroRetrieve the current keystroke macro.
inq_keystroke_statusDetermine keystroke macro status.
inq_local_keyboardRetrieve local keyboard identifier.
inq_mouse_actionRetrieve the keyboard mouse handler.
inq_mouse_typeRetrieve the button type.
inq_remember_bufferDetermine the keystroke buffer name.
int_to_keyConvert an keycode to mnemonic key string.
key_listRetrieve keyboard bindings.
key_to_intConvert key name to a code.
keyboard_flushFlush the keyboard buffer.
keyboard_popPop a keyboard from the keyboard stack.
keyboard_pushPush a keyboard onto the keyboard stack.
keyboard_typeablesAssign self_insert to all typeable keys.
load_keystroke_macroLoad a recorded macro from a file.
pausePause keystroke definition.
playbackReplay a keystroke macro.
processInvoke a Grief engine.
push_backPush back a character into the keyboard.
read_charRead next key from the keyboard.
rememberStart remembering keystrokes.
save_keystroke_macroSave the current keystroke macro.
set_kbd_nameSet the keyboard name.
set_mouse_actionSet keyboard mouse handler.
set_mouse_typeSets the mouse type.
undoUndo previous edit operations.
use_local_keyboardAssociate a keyboard with a buffer.

Macros

assign_to_key

int assign_to_key([string key],
[string macro])

Assign command to key or key sequence.

Description

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.

Parameters

keyString identifying the particular keystroke that is being assigned.
macroString 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.

Key Sequences

Generally keys are defined using their associated mnemonic possiblity prefixed with one or modifiers enclosed within a set of “<>” brackets, examples.

  • <F1>
  • <Ctrl-F1>
  • <Alt-Ctrl-Up>.

The following are the set of supported modifiers

  • Shift - Key Shift, for example a to Z.
  • Ctrl - Control Key.
  • Alt - Alt Key.
  • Meta - Alias for Alt.
  • Keypad - Keypad key variate.

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.

#xxxSubstitutes the # lead sequence of digits with the represent value.  For example #123 result in the key code 123.
^xThe ^ 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

Note:

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.

Returns

The assign_to_key returns the key value assigned to sequence, otherwise -1 if the key sequence is invalid or the operation aborted.

Portability

n/a

See Also

key_to_int

copy_keyboard

int copy_keyboard(int kbdid,
  [string cmd ...])

Copy a keyboard.

Description

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.

Parameters

kbdbidKeyboard 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.

Returns

The copy_keyboard() primitive returns the Keyboard identifier of the new keyboard.  On error 0 is returned if the commands given are not found.

Portability

n/a

See Also

keyboard_push, keyboard_pop, assign_to_key

get_mouse_pos

void get_mouse_pos(  [int &x],
[int &y],
[int &winnum],
 [int &line],
[int &col],
 [int &where],
[int &region],
[int &event])

Retrieve last mouse action.

Description

The get_mouse_pos() primitive retrieves the details of the last mouse action.

Note:

The details returned are only valid immediately after the macro assigned to a button press event.  Any subsequent calls to read_char or process will overwrite the internal values.

Parameters

x, yScreen coordinates.
winnumOptional 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, colOptional integer variables which shall be populated with the translated window coordinates, otherwise -1 if no window was mapped.
whereWhere the cursor is located within the window.
regionCursor position relative to any marked regions.
eventAssociated mouse event.
Where
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.
Region
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

Returns the time since the previous mouse event.

Portability

n/a

See Also

process_mouse, translate_pos

input_mode

int input_mode(int char,
int flag)

Effect of certain system keys.

Description

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).

Parameters

charInteger value of the ascii character to be effected.
flagsBoolean flag, if true enable the specified character to flow thru to GRIEF otherwise false to reset the default behaviour.

Returns

The input_mode() primitive returns 1 if character previously enabled; zero otherwise.

Portability

n/a

See Also

inq_keyboard

inq_assignment

string inq_assignment(int|string val,
 [int tokey = FALSE])

Get key assignment for function.

Description

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.

Parameters

valString 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.
tokeyOptional 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.

Returns

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.

For command to key sequence enabled when tokey is non-zero

a list of the valid key sequences for the command.  The list elements are formatted with the following separators:

-orSeparates different ways of specifying a single key.
-andSeparates keys in a multi-key sequence.
-alsoSeparates multiple (different) key sequences.

Portability

n/a

See Also

assign_to_key

inq_kbd_char

int inq_kbd_char()

Peek at the keyboard.

Description

The inq_kbd_char() primitive determines whether a character is available to be retrieved from the keyboard using read_char.

Note:

This primitive only tests the internal look ahead buffer not the external terminal and/or keyboard stream.

Parameters

none

Returns

The inq_kbd_char() primitive returns non-zero if one or more characters are available, otherwise 0 if the keyboard buffer is empty.

Portability

n/a

See Also

read_char

inq_kbd_flags

int inq_kbd_flags()

Get keyboard key flags.

Description

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

Parameters

none

Returns

Always returns 0.

Portability

Provided only for BRIEF compatibility.

See Also

inq_kbd_char

inq_kbd_name

string inq_kbd_name([int kbdid])

Retrieve the assigned keyboard name.

Description

The inq_kbd_name() primitive retrieves the name assigned to the keyboard kbdid using <set_kdb_name>.

Parameters

kbdidOptional integer keyboard identifier, if omitted the current keyboard shall be referenced.

Returns

The inq_kbd_name() primitive retrieves the keyboard name otherwise an empty string is none has been assigned.

Portability

n/a

See Also

set_kbd_name

inq_keyboard

int inq_keyboard()

Retrieve the keyboard identifier.

Description

The inq_keyboard() primitive retrieves the identifier associated with the current keyboard.

Parameters

none

Returns

The inq_keyboard() primitive returns the current keyboard identifier.

Portability

n/a

See Also

keyboard_pop, keyboard_push

inq_keystroke_macro

string inq_keystroke_macro([int macroid],
[int &bufnum])

Retrieve the current keystroke macro.

Description

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.

Note:

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.

Parameters

macroidOptional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised.
bufnumOmitted integer variable if supplied shall be populated with the associated buffer number.

Returns

nothing

Portability

Under BRIEF this primitive behaved like the functionality available via inq_keystroke_status.

See Also

remember, load_keystroke_macro

inq_keystroke_status

int inq_keystroke_macro([int &macroid])

Determine keystroke macro status.

Description

The inq_keystroke_macro() primitive determines whether keystroke macro record or playback is active.

Parameters

macroidOptional integer variable if supplied shall be populated with the current macro identifier.

Returns

The inq_keystroke_macro() primitive returns greater than zero if a keystroke macro is being recorded or played back.

Portability

Under BRIEF this primitive is named inq_keystroke_macro.

See Also

remember, playback

inq_local_keyboard

int inq_local_keyboard()

Retrieve local keyboard identifier.

Description

The inq_local_keyboard() primitive retrieves the identifier associated with current local keyboard.

Parameters

none

Returns

The inq_local_keyboard() primitive returns the associated keyboard identifier, otherwise 0 if none is available.

Portability

n/a

See Also

use_local_keyboard

inq_mouse_action

string inq_mouse_action()

Retrieve the keyboard mouse handler.

Description

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.

Parameters

none

Returns

Returns the current mouse action.

Portability

n/a

See Also

set_mouse_action

inq_mouse_type

int inq_mouse_type()

Retrieve the button type.

Description

The inq_mouse_type() primitive retrieves the current mouse type.

Parameters

none

Returns

Returns the current mouse type.

Value
Description
0
No mouse.
1
One-button mouse.
2
Two-button mouse.
3
Three-button mouse.

Portability

n/a

See Also

inq_remember_buffer

string inq_remember_buffer([int macroid])

Determine the keystroke buffer name.

Description

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.

Parameters

macroidOptional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised.

Returns

The inq_remember_buffer() primitive returns the buffer name associated with the remember buffer.

Portability

n/a

See Also

remember

int_to_key

string int_to_key(int key)

Convert an keycode to mnemonic key string.

Description

The int_to_key() primitive generates the corresponding mnemonic representation for the specified keycode key; which can be used by assign_to_key

Parameters

keyInteger keycode.

Returns

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.

Portability

n/a

See Also

assign_to_key

key_list

list key_list(int kbdid,
  [int self_inserts = 0],
 [int bufnum])

Retrieve keyboard bindings.

Description

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.

Parameters

kbdidOptional integer keyboard identifier.  If omitted then firstly the local keyboard if available is referenced otherwise the current keyboard is referenced.
self_insertsOptional boolean flag when non-zero keys assigned to self_insert shall be including, otherwise they are omitted from the generated list.
bufnumOptional buffer identifier to source the secondary local keyboard.  If omitted then the local keyboard map of the current buffer is used.

Returns

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.

Portability

n/a

See Also

keyboard_pop, keyboard_push

key_to_int

int key_to_int(string key,
int raw)

Convert key name to a code.

Description

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.

Warning:

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;
:

Parameters

keyString contains a single mnemonic key description, for example (“i” or “<Ctrl-z>”).
rawOptional 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.

Returns

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.

Portability

n/a

See Also

assign_to_key, int_to_key

keyboard_flush

void keyboard_flush()

Flush the keyboard buffer.

Description

The keyboard_flush() primitive flushs the keyboard input buffer, consuming any pending input, permanently removing the keystrokes.

Parameters

none

Returns

nothing

Portability

n/a

See Also

inq_kbd_char, read_char

keyboard_pop

void keyboard_pop([int save = FALSE])

Pop a keyboard from the keyboard stack.

Description

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.

Parameters

saveOptional boolean value, if specified as true the keyboard resource is retained otherwise if false or omitted it is discarded.

Returns

nothing

Portability

n/a

See Also

keyboard_push, inq_keyboard

keyboard_push

void keyboard_push([int kbdid])

Push a keyboard onto the keyboard stack.

Description

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.

Defaults

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

Parameters

kbdidInteger 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.

Returns

The keyboard_push() primitive returns the identifier of the referenced keyboard, otherwise -1 on error.

Example

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();

Portability

n/a

See Also

inq_keyboard, keyboard_pop, keyboard_typeables, process

keyboard_typeables

int keyboard_typeables()

Assign self_insert to all typeable keys.

Description

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.

Parameters

none

Returns

nothing

Portability

n/a

See Also

inq_keyboard

load_keystroke_macro

int load_keystroke_macro(string def)

Load a recorded macro from a file.

Description

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.

Parameters

macroString containing the macro definition.

Returns

The load_keystroke_macro() primitive returns the newly associated macro identifier, otherwise -1 on error.

Portability

n/a

See Also

inq_keystroke_macro

pause

void pause()

Pause keystroke definition.

Description

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.

Parameters

none

Returns

nothing

Portability

n/a

See Also

remember

playback

int playback([int macroid])

Replay a keystroke macro.

Description

The playback() primitive replays the previously saved keyboard macro macro.

Parameters

macroidOptional integer macro identifier specifies the keyboard against which to derive the buffer name, if omitted the current macro identifier is utilised.

Returns

The playback() primitive returns greater than or equal to zero if playback was successful, otherwise less than zero on error.

Portability

n/a

See Also

remember

process

void process()

Invoke a Grief engine.

Description

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.

Parameters

none

Returns

nothing

Portability

n/a

See Also

exit, suspend

push_back

void push_back(int key,
  [int front],
 [int x],
 [int y])

Push back a character into the keyboard.

Description

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.

Parameters

keyKey code.
frontOptional 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, yMouse position, required when pushing back mouse events.

Returns

nothing

Portability

Mouse support is a GriefEdit extension.

See Also

inq_kbd_char, key_to_int, read_char

read_char

void read_char([int timeout = 0],
[int mode = 0])

Read next key from the keyboard.

Description

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.

Parameters

timeoutOptional 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.
modeOptional request mode, see above.

Returns

The read_char() primitive returns the key-code, otherwise -1 on a timeout.

Portability

Use of a ‘-’1 timeout value is required to emulate BRIEF.

See Also

int_to_key, inq_kbd_char, inq_kbd_flags

remember

int remember([string|int overwrite],
[int macroid])

Start remembering keystrokes.

Description

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.

Note:

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.

Parameters

overwriteOptional 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.
macroidOptional integer macro identifier specifies the keyboard against which to store the keystrokes, if omitted the next free keyboard identifier is utilised.

Returns

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.

Portability

n/a

See Also

pause

save_keystroke_macro

int save_keystroke_macro(string filename)

Save the current keystroke macro.

Description

The save_keystroke_macro() primitive saves the current remembered keystrokes macro to the specified file filename.

Parameters

filenameString 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.

Returns

The save_keystroke_macro() primitive returns greater than zero on success, otherwise -1 on error.

See Also

playback, remember

set_kbd_name

void set_kbd_name(string name,
 [int kbdid])

Set the keyboard name.

Description

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.

Parameters

nameString containing the name to be assigned.  If empty the current name shall be cleared.
kbdidOptional integer keyboard identifier, if omitted the current keyboard shall be referenced.

Returns

nothing

Portability

n/a

See Also

inq_kbd_name

set_mouse_action

int set_mouse_action(string mouse_handler)

Set keyboard mouse handler.

Description

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;
}
}

Parameters

mouse_handlerA string containing the name of the function to be associated with the current keyboard.

Returns

Returns the previous mouse action.

Portability

n/a

See Also

inq_mouse_action, inq_keyboard

set_mouse_type

int set_mouse_type()

Sets the mouse type.

Description

The set_mouse_type() primitive sets the mouse type.

Parameters

typeInteger stating the current mouse type.
Value
Description
0
No mouse.
1
One-button mouse.
2
Two-button mouse.
3
Three-button mouse.
button1Option 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.

Returns

none

Portability

n/a

See Also

inq_mouse_type

undo

int undo([int move],
[int pastwrite = -1],
[int redo = FALSE])

Undo previous edit operations.

Description

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?

Note:

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.

Parameters

moveOptional boolean value, if true then all buffer operations up the last buffer modification are undone.
pastwriteOption 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.
redoOptional boolean value, if true the previous undo action shall be undone.

Returns

The undo() primitive returns the number of operations undo; this is GriefEdit extension.

Portability

n/a

See Also

redo

use_local_keyboard

int use_local_keyboard(int kbdid)

Associate a keyboard with a buffer.

Description

The use_local_keyboard() primitive cause the current keyboard to be associated with the current buffer.

Parameters

kbdidKeyboard identifier.

Returns

The use_local_keyboard primitive return 0 on success otherwise -1 on error.

Portability

n/a

See Also

inq_local_keyboard, keyboard_pop, keyboard_push

$Id: $

To send feedback on this topic email: grie.nosp@m.fedit@gmai.nosp@m.l.com

Copyright © Adam Young All Rights Reserved.

int assign_to_key([string key],
[string macro])
Assign command to key or key sequence.
int copy_keyboard(int kbdid,
  [string cmd ...])
Copy a keyboard.
void get_mouse_pos(  [int &x],
[int &y],
[int &winnum],
 [int &line],
[int &col],
 [int &where],
[int &region],
[int &event])
Retrieve last mouse action.
int input_mode(int char,
int flag)
Effect of certain system keys.
string inq_assignment(int|string val,
 [int tokey = FALSE])
Get key assignment for function.
int inq_kbd_char()
Peek at the keyboard.
int inq_kbd_flags()
Get keyboard key flags.
string inq_kbd_name([int kbdid])
Retrieve the assigned keyboard name.
int inq_keyboard()
Retrieve the keyboard identifier.
string inq_keystroke_macro([int macroid],
[int &bufnum])
Retrieve the current keystroke macro.
int inq_keystroke_macro([int &macroid])
Determine keystroke macro status.
int inq_local_keyboard()
Retrieve local keyboard identifier.
string inq_mouse_action()
Retrieve the keyboard mouse handler.
int inq_mouse_type()
Retrieve the button type.
string inq_remember_buffer([int macroid])
Determine the keystroke buffer name.
string int_to_key(int key)
Convert an keycode to mnemonic key string.
list key_list(int kbdid,
  [int self_inserts = 0],
 [int bufnum])
Retrieve keyboard bindings.
int key_to_int(string key,
int raw)
Convert key name to a code.
void keyboard_flush()
Flush the keyboard buffer.
void keyboard_pop([int save = FALSE])
Pop a keyboard from the keyboard stack.
void keyboard_push([int kbdid])
Push a keyboard onto the keyboard stack.
int keyboard_typeables()
Assign self_insert to all typeable keys.
int load_keystroke_macro(string def)
Load a recorded macro from a file.
void pause()
Pause keystroke definition.
int playback([int macroid])
Replay a keystroke macro.
void process()
Invoke a Grief engine.
void push_back(int key,
  [int front],
 [int x],
 [int y])
Push back a character into the keyboard.
void read_char([int timeout = 0],
[int mode = 0])
Read next key from the keyboard.
int remember([string|int overwrite],
[int macroid])
Start remembering keystrokes.
int save_keystroke_macro(string filename)
Save the current keystroke macro.
void set_kbd_name(string name,
 [int kbdid])
Set the keyboard name.
int set_mouse_action(string mouse_handler)
Set keyboard mouse handler.
int set_mouse_type()
Sets the mouse type.
int undo([int move],
[int pastwrite = -1],
[int redo = FALSE])
Undo previous edit operations.
int use_local_keyboard(int kbdid)
Associate a keyboard with a buffer.
void nothing()
Noop.
int register_macro(int type,
 string macro,
 [int local = FALSE])
Register a callback procedure.
void process_mouse(   [int b1],
 [int b2],
 [int b3],
int x,
int y)
Process mouse event.
int translate_pos(int x,
int y,
  [int &winnum],
 [int &line],
 [int &col])
Convert window coordinates.
void self_insert([int character])
Insert a character as if it was typed.
void change_window([int direction],
[string message])
Selects a new window.
int move_edge([int direction],
[int amount])
Modify a window.
int create_edge([int direction])
Create an edge, splitting the window.
int delete_edge([int direction])
Delete an edge, combining a split window.
int search_fwd(string pattern,
 [int re],
 [int case],
  [int block],
 [int length])
Buffer search.
int translate(string pattern,
string replacement,
  [int global],
 [int re],
 [int case],
  [int block],
 [int forward])
Buffer search and replace.
int load_macro(string filename,
 [int reload = 1])
Load a macro object.
declare execute_macro([string cmd],
...)
Invokes a command by name.
int paste([int syspaste = FALSE])
Insert scrap buffer at cursor location.
int end_of_line()
Goto end of line.
int down([int lines = 1])
Move position down one line.
int left([int columns = 1],
[int wrap = TRUE])
Move position left one charcter.
int right([int columns = 1],
[int wrap = TRUE])
Move position right one character.
int beginning_of_line()
Goto beginning of line.
int up([int lines = 1])
Move position up one line.
int delete_block()
Deleted selected region.
int cut([int append = FALSE],
[int syscopy = FALSE])
Cut marked area to scrap.
int copy([int append = FALSE],
[int keep = FALSE])
Copy marked area to scrap.
int page_down([int pages = 1])
Move position down a page.
int page_up([int pages = 1])
Move position up a page.
int end_of_window()
Goto end of the current window.
int end_of_buffer()
Move cursor to end of current buffer.
int top_of_window()
Goto top of the current window.
int top_of_buffer()
Move cursor to start of current buffer.
void exit([string y_or_w])
Exit current process level.
int drop_bookmark([int bookid],
[string yesno],
 [int bufnum],
[int line],
[int column],
[int local = FALSE])
Create or update a bookmark.
int mark([int type = MK_NORMAL])
Toggle the anchor status.
void delete_line()
Delete current line.
int edit_file(...)
Edit a file.
int goto_line([int lineno])
Move to a particular line.
int insert_mode([int value],
[int bufnum])
Set the buffer insert/overstrike mode.
int goto_bookmark(int bookid =  NULL,
  [int &bufnum],  
 [int &line],  
 [int &column]  )
Seek a bookmark.
void delete_to_eol()
Delete to end-of-line.
int output_file([string filename])
Change the output file-name.
int print()
Print formatted string to stdout.
int read_file([string filename],
 [int glob = TRUE],
[string encoding = NULL])
Read into the current buffer.
int version([int major | string machtype],
 [int min],
[int edit],
[int release],
[string machtype],
 [string compile],
[int cmversion],
 [string features],
[string build])
Version information.
int write_buffer(  [string filename],
[int flags],
[string encoding])
Write to buffer content.
int shell([string cmd],
[int use_shell],
 [string completion],
 [string stdin],
[string stdout],
[string stderr],
 [int mode],
[string spec])
Spawn a sub-shell process.
void suspend()
Suspend current process.
void set_buffer_flags([int bufnum],
 [string|int or_mask],
[string|int and_mask],
 [int set = 1])
Set buffer flags.
void redo()
Redo an undo operation.