Articles

learn more about encryption

Creating Custom Virtual Keyboard

Virtual keyboard is an on-screen window that allows entering a password securely, so that no keyboard logger could intercept it. It looks like a real keyboard; the only difference is that you enter your password by clicking the keys with your mouse.

Virtual keyboard

Kryptel already includes quite a number of virtual keyboards; if there is no keyboard for your language, you can easily create it. However you can do a lot more than just creating another screen copy of your keyboard. Kryptel's virtual keyboard component is powerful enough to create very non-standard keyboard layouts.

As an example we will create a rather weird keyboard for a 'geometric' language, which contains eight 'letters': square, circle, triangle, and diamond, in hollow and filled variations.

Example Geomteric keyboard

It allows entering passwords containing 'geometric' characters.

Kryptel password window

In order to add the Geometric keyboard to the list of the available keyboards, download files geometric.templ and geometric.kbd, and store them in the keyboard folder "C:\Program Files\Kryptel\Keyboards".

Defining Keyboard

Virtual keyboard definition is a pair of files – a keyboard template file and a key definition file that reside in the Keyboards subfolder of the Kryptel program folder (usually "C:\Program Files\Kryptel\Keyboards").

Template file defines the position and the size of the keyboard keys. If you create a keyboard for a natural language, you probably won't need one, because there are only two keyboard layouts: the US layout, defined in standard.templ, and the European layout (euro.templ), which the rest of the world are using. However if you create a custom keyboard, like our 'geometric' one, you will likely need a non-standard layout.

Key definition file assigns values to the keys and defines special control keys. It always bases on some template, which keys it defines. For example, en-us.kbd defines English US keyboard based on standard.templ.

Creating New Layout

First thing to do is to create a template (or layout) file. It defines key rows top to bottom, and keys for each row, left to right. We will need only two commands – the @row command, which starts a new row, and the # command, which defines a key.

'Geometric' keyboard example

First row

@row
#keySquare
#keyTriangle
#keyCircle
#keyDiamond
#keyBackspace = 1.8
#keyEnter = 2.2

Second row

@row
#keyShift = 2
#keySpace = 3
#keyLanguageSelector =>

Key identifier that immediately follows the # command, may be any combination of Latin letters and digits. It is used by the associated key definition file to assign a value to the key, and naturally, each key identifier must be unique.

Key definition command may have a width argument – a floating-point number, specifying the key width in height units. If the argument is missing, it is assumed to be 1, that is, the command defines a square key. For instance, keyShift is a double-sized key; its width is two times larger than its height. Note that on the screenshot above it takes slightly less space than the two keys above it because of the inter-key gap.

The right angle bracket > as the width argument (see the definition of keyLanguageSelector) has a special meaning. It aligns the right side of the key with the end of the previous row. The > argument is not allowed in the first row, and can be used only with the last key of the row.

If the first character of a line is not @ or #, the line is considered a comment and ignored.

Defining Keys

Now that we have defined the key layout, it is a time to assign character codes to the keys of our newly created keyboard. Below is shown the contents of the key definition file for our example keyboard (as in the case of template file, any line not starting with @ or # is treated as a comment).

*
* 'Geometric' keyboard example
*

@name = Geometric

@template = geometric.templ

@switcher = keyLanguageSelector


*
* Modifiers and special keys
*

@mod = Shift, keyShift, 21d1 53 68 69 66 74, auto

@special = keyBackspace, 8, 2190
@special = keyEnter, D, 21b5
@special = keySpace, 20, 20


*
* Key definitions
*

#keySquare = 25a1 | 25a0 & Shift
#keyTriangle = 25b3 | 25b2 & Shift
#keyCircle = 25cb | 25cf & Shift
#keyDiamond = 25c7 | 25c6 & Shift

Key definition file consists of two parts – header and key list. Header commands are started with @; key definitions are started with #. Header ends when first key definition is encountered; any header @ command is illegal from that point.

The @name command sets the name of the keyboard. This name will appear on the language switcher and in the language list. It is a mandatory command every key definition file must include.

The @template command specifies the linked keyboard template file. It is also a mandatory command.

The @switcher command defines a special key, which shows the language (and keyboard size) selector window. The command argument is the key identifier defined in the linked template file. Although this command is optional, it is strongly recommended to include the selector key in every keyboard, otherwise it would not be possible for the user to choose another keyboard. If there is no such key, you will need to delete the settings file "C:\Users\<your name>\AppData\Roaming\Inv Softworks\Kryptel Common Data\Kryptel.xml" in order to reset the keyboard to the default English US one.

Modifiers

The Geometric keyboard defines only one modifier key:

@mod = Shift, keyShift, 21d1 53 68 69 66 74, auto

Modifier is a key that does not generate any character code, but changes the behavior of other keys instead. An example of a modifier is the keyboard Shift key. The format of the @mod command is

@mod=name,key,inscription[,auto]

The first argument is the modifier name, and the second is the key identifier. Note that a modifier may be defined by several @mod commands. For instance, the Shift modifier of the English US keyboard uses two keys – Left Shift and Right Shift.

The inscription argument specifies how the key should be marked, and must be either a string in quotes, or a sequence of hexadecimal codes. The Shift key on the Geometric keyboard is inscribed with the double up arrow character (code 21D1) and string “Shift” (codes 53 68 69 66 74).

The last argument auto specifies the modifier should reset automatically after any character key is pressed. This argument is optional; if it is missed, the keyboard will be in the modified state until the modifier is pressed again.

Special Keys

Special key is a key that generated a character value like an ordinary key, but neither is affected by modifiers, nor affects them (that is, it does not reset auto modifiers). The format of the @special command is

@special=key,value,inscription

key is key identifier defined in the associated template file,
value is the character value that the key generates,
inscription is either a string in quotes, or a sequence of hexadecimal codes.

Our Geometric keyboard defines three special keys: Backspace, Enter, and Space.

Key List

Key list is a sequence of # commands, assigning character values to the key identifiers, defined in the associated template file. The format of key definition is

#key = state1 | state2 | state3 ...

key is the key identifier, and state defines generated character codes for a specific combination of modifiers. Each state has the format

values & mod1,mod2,...,modN % inscription

values is a sequence of codes separated by commas, where each value is either a character in apostrophes, or a hexadecimal code (2 to 4 hex digits).

The & part is optional. If it presents, it specifies which modifiers must be active to generate the given values. If this part is missed, it specifies the generated values for the state with all the modifiers inactive.

The % part is also optional, and specifies the key inscription. If a custom inscription is present, it should be either a string enclosed in quotes, or a sequence of space-separated hex codes.

Our ‘geometric’ keys are used in combination with only one modifier and have no custom inscriptions, so the key definitions are fairly simple

#keySquare = 25a1 | 25a0 & Shift
#keyTriangle = 25b3 | 25b2 & Shift
#keyCircle = 25cb | 25cf & Shift
#keyDiamond = 25c7 | 25c6 & Shift

There are only two states for each key – unshifted and shifted. Note that there is no ‘default’ value; if we define keySquare as

#keySquare = 25a1

it does not mean that it generates code 25A1 in any state; this definition means that the key generates code 25A1 in the unshifted state, and in the shifted state this key is a blank uninscribed key generating no code.

This concludes our example demonstrating the creation of a custom virtual keyboard. Both the keyboard files can be downloaded from geometric.templ and geometric.kbd. Pleace these files to the keyboard folder "C:\Program Files\Kryptel\Keyboards" in order to make the example keyboard selectable.

Appendix: Character Hexadecimal Values

When creating a virtual keyboard, especially a non-standard virtual keyboard, you will often need to find out characters' hexadecimal values. Windows includes a standard Character Map utility, which lets you see the hecadecimal code of a character, and its graphical representation.

Character Map

As can easily see on the screenshot above, the hexadecimal code of the black box character is 25A0.

In order to open Character Map, run "C:\Windows\System32\CharMap.exe" or press Start and enter charmap in the Search field.

Appendix: Keyboard Template Commands

Keyboard template support three commands, @row must be the first command in the template. Any command before the first @row command is illegal.

@row
Starts a new key row. A typical keyboard has five key rows so the corresponding template includes five @row commands.
@space[=x]
Insert a blank space in the current key row. The optional x parameter is a floating-point number specifying the space width in height units. If the parameter is missing, it is assumed to be 1, that is, the key will be square.
#name[=x]
Inserts a key into the current row and assigns it a name. Like in the @space command, the x parameter is optional and specifies the key width. If x is not a number, but the right angle bracket, then the right side of the key should be aligned with the right side of the rightmost key in the previous row.

Any line not starting with @ or # is treated as a comment.

Appendix: Keyboard Definition Commands

A keyboard definition file consists of two sections: a header section (@ commands) and a key list (# commands). The key list section starts with first occurence of a # command. After the first occurence of a # command, any @ command is illegal.

Any line not starting with @ or # is treated as a comment.

If the file contains national characters (for instance, in the argument of the @localname command), it should be saved in either UTF-8 or UTF-16.

Header Section Commands

@template=filename
A mandatory command specifying the associated keyboard template. This command must appear before @switcher and @mod commands (which use key names).
@name=name
A mandatory command specifying the keyboard name, for example @name = German
@localname=name
An optional localized keyboard name, for example @localname = Deutsch
@switcher=key
Optional. Specifies a key, which is to be used as a language switcher.
@mod=name,key,inscription[,auto]
Specifies a modifier key (for example, Shift). The name is the modifier name, and key is the template key identifier. Inscription is either a string enclosed in quotes, or a sequence of space-separated hexadecimal codes. The optional auto parameter specifies an auto reset key (such as Shift or Alt); missing auto parameter specifies a manual reset key (such as Caps Lock).
@special=key,value,inscription
Defines a special key like Enter ot Backspace. A special key generates a character code like an ordinary key. The difference is that special key is not affected by modifiers, and does not reset active auto modifiers. The key parameter is a template key identifier; value is a hexadecimal (1 to 4 digits) character value. Inscription is either a string enclosed in quotes, or a sequence of space-separated hexadecimal codes.

Key Definition Command

The key definition command # has the following format:

#key=values [&mod1[,mod2[...[,modN]]]] [%inscription] [|values...]

key is a template key identifier.

The values parameter is a sequence of codes, separated by commas, where each value is either a character in apostrophes, or a hexadecimal code (2 to 4 hexadecimal digits). If the value is a character in apostrophes, the character can't be vertical bar, percent sign, ampersend, or comma. In order to represent these characters, use respective hexadecimal codes 7C, 25, 26, and 2C.

mod is a modifier name, declared in a previous @mod command.

If a custom inscription is present, it should be either a string enclosed in quotes, or a sequence of space-separated hexadecimal codes.

Example:

#LetterA = 'a' | 'A' &Shift | 'A' &CapsLock | 'a' &CapsLock,Shift

If some modifier combination is not specified, the key in that state will be a blank unmarked key generating no code.

The first # command terminates the header and starts the key list. Any header @ command is illegal from that point.