CONFIGURE KEY is used to redefine key assignments. A single key can have more than one definition based on different shift-key combinations (Shift, Ctrl, Alt) plus the states of Caps Lock, CMODE ON/OFF, and the currently active soft menu. A key definition consists of these four parts:
-
The key-number (numeric value of the keyboard key pressed)
-
The shift conditions to be considered (masked) when the key is pressed
-
The value those shift conditions must have
-
The (2nd char) function to execute when the key is pressed with the desired combination of shift conditions
CONFIGURE KEY is therefore implemented with four options to set the four required values to define a key. Note that function in the example below is the value of the 2nd character function list which can be from 0-255. So the the values 256, 257, and 258 are merely codes above this range to select the other three required options of CONFIGURE KEY as follows:
CONFIGURE KEY key-number TO 256 ! removes all prior definitions
CONFIGURE KEY shift-mask TO 257 ! Set shift-mask
CONFIGURE KEY shift-value TO 258 ! Set shift-value
CONFIGURE KEY key-number TO function ! Assign the new function (2nd char value)
Note that it is recommended to remove prior definitions before redefining a key. This is because prior Mask values may allow the old definition to still function or prevent the new function from working.
The key-number for Function Keys F1-F12 are respectively 112-123. Also a KeyNum utility is included with HTBasic to determine the key-number for any keyboard key. KeyNum.exe can be found in the HTBasic install folder. Double-click on it and press the key of interest to see its value, then press Alt+F4 to quit.
Shift-mask and shift-value specify what combination of shift conditions apply to a key press. The table below shows the values that you must sum up for combining the various shift-mask and shift-value options.
Shift-Key Combinations
As noted, the keyboard has three "shift" keys: Shift, Alt, and Ctrl, the combination of which, together with the states of Caps Lock, CMODE ON/OFF, and the active softkey menu (System, User1, User2, or User3) determine which function a Function Key press will execute. The following table lists the individual values of shift-states and shift-values which must each be summed to indicate the combination that applies to a Function key's assigned function:
Shift Conditions
|
Shift-mask [bits]
|
Shift-value
|
Ignore all shift conditions
|
[000000000000] 0
|
[000000000000] 0
|
Shift key not pressed
|
[000000000001] 1
|
[000000000000] 0
|
Shift key pressed
|
[000000000001] 1
|
[000000000001] 1
|
Ctrl key not pressed
|
[000000000010] 2
|
[000000000000] 0
|
Ctrl key pressed
|
[000000000010] 2
|
[000000000010] 2
|
Alt key not pressed
|
[000000001000] 8
|
[000000000000] 0
|
Alt key pressed
|
[000000001000] 8
|
[000000001000] 8
|
Caps Lock off
|
[000001000000] 64
|
[000000000000] 0
|
Caps Lock on
|
[000001000000] 64
|
[000001000000] 64
|
System Menu
|
[011100000000] 1792
|
[000000000000] 0
|
User1 Menu
|
[011100000000] 1792
|
[000100000000] 256
|
User2 Menu
|
[011100000000] 1792
|
[001000000000] 512
|
User3 Menu
|
[011100000000] 1792
|
[001100000000] 768
|
KBD CMODE OFF
|
[100000000000] 2048
|
[000000000000] 0
|
KBD CMODE ON
|
[100000000000] 2048
|
[100000000000] 2048
|
Remember, only one of the four possible menus may be specified: System, User1, User2, or User3. Note also it may not be a good idea to use the Ctrl key because that prevents its conventional use (such as inserting a function key’s two characters into a string literal rather than execute it.)
CONFIGURE KEY key TO function specifies the Keyboard
function to assign to the
key. Consult the "
Shortcut Key List" for the second characters used by each HTBasic function. The numeric value of the 2nd character is used as the value for
function. For example, the table lists "V" as the 2nd character for the Previous Line (DOWN) keyboard function. If you wish to define a key to do the DOWN function, substitute NUM("V") for function.
The following example shows how to swap the actions (both shifted and unshifted) of the UP/END and DOWN/BEGIN keys:
Key Function
|
Key Name
|
Keyboard
|
Next Line
|
UP
|
á
|
End of output/program
|
END
|
Shift+á
|
Previous Line
|
DOWN
|
â
|
Begin of output area
|
BEGIN
|
Shift+â
|
After redefining the keys, the definitions will be:
Key Function
|
Key Name
|
Keyboard
|
Next Line
|
UP
|
â
|
End of output/program
|
END
|
Shift+â
|
Previous Line
|
DOWN
|
á
|
Begin of output area
|
BEGIN
|
Shift+á
|
The values for the á and â keys are 38 and 40, respectively. You can get key values with the KeyNum utility.
!Define Up-Arrow Key
CONFIGURE KEY 38 TO 256 !Remove old á key defs
CONFIGURE KEY 1 TO 257 !Shift mask: Shift Key
CONFIGURE KEY 0 TO 258 !Shift value: Not pressed
CONFIGURE KEY 38 TO NUM("V") !á key is DOWN
CONFIGURE KEY 1 TO 257 !Shift mask: Shift key
CONFIGURE KEY 1 TO 258 !Shift value: Pressed
CONFIGURE KEY 38 TO NUM("T") !Shift-á is BEGIN
!Define Down-Arrow Key
CONFIGURE KEY 40 TO 256 !Delete previous â key defs
CONFIGURE KEY 1 TO 257 !Shift mask: Shift key
CONFIGURE KEY 0 TO 258 !Shift value: Not pressed
CONFIGURE KEY 40 TO NUM("^") !â key is up
CONFIGURE KEY 1 TO 257 !Shift mask: Shift key
CONFIGURE KEY 1 TO 258 !Shift value: Pressed
CONFIGURE KEY 40 TO NUM("W") !Shift-â is END
END
If the Shift-mask is not specified, the last Shift-mask specified will be used. If no Shift-mask has ever been specified, a value of 0 is used. The same is true for the Shift-value.
It is also sometimes useful to remove HTBasic key definition so the key reverts to its default use. For example, HTBasic defines Alt+F4 as Pause Program. If you wish to use it to Quit HTBasic, you must first remove the current definition.
Assuming F4 is key number 115, the following example deletes all definitions for F4, including Alt-F4, then redefines all definitions except Alt-F4:
DATA 115,256,257,258
READ F4,Remove,Mask,Value
CONFIGURE KEY F4 TO Remove ! Remove all F4 definitions
CONFIGURE KEY 3849 TO Mask ! KBD CMODE(2048) + Menu(1792) + Alt(8) + Shift(1) = 3849
CONFIGURE KEY 0 TO Value ! KBD CMODE OFF(0) + System(0) = 0
CONFIGURE KEY F4 TO NUM("P") ! Pause
CONFIGURE KEY 1 TO Value ! Value: KBD CMODE OFF(0) + System(0) + Shift(1) = 1
CONFIGURE KEY F4 TO NUM("!") ! Stop
CONFIGURE KEY 256 TO Value ! Value: KBD CMODE OFF(0) + User1(256) = 256
CONFIGURE KEY F4 TO NUM("4") ! K4
CONFIGURE KEY 512 TO Value ! Value: KBD CMODE OFF(0) + User2(512) = 512
CONFIGURE KEY F4 TO NUM("c") ! K12
CONFIGURE KEY 768 TO Value ! Value: KBD CMODE OFF(0) + User3(768) = 768
CONFIGURE KEY F4 TO NUM("$") ! ANY CHAR
CONFIGURE KEY 2057 TO Mask ! Mask: KBD CMODE(2048) + Alt(8) + Shift(1) = 2057
CONFIGURE KEY 1 TO Value ! Value: KBD CMODE OFF(0) + Shift(1) = 1
CONFIGURE KEY F4 TO NUM("D") ! Edit
CONFIGURE KEY 2048 TO Value ! Value: KBD CMODE ON(2048) = 2048
CONFIGURE KEY F4 TO NUM("3") ! K3
CONFIGURE KEY 2049 TO Value ! Value: KBD CMODE ON(2048) + Shift(1) = 2049
CONFIGURE KEY F4 TO NUM("d") ! K13
END