Search
Virtual Keys

Key Types

Keys in the Virtual Keyboard for JavaScript can be regular or special. A regular key sends a character or longer string as input to focused control and can display several labels (e.g. for lower and upper case letters). Its content specifies the text to send when the key is pressed. Special keys are those that do not send any character to the input element but modify the content that is sent from regular keys or affect how JsKeyboard responds to user actions: Shift, NumLock, Insert, Delete, CapsLock etc.

How to Create a Key

Keys in the virtual keyboard are represented by instances of the Key class or members of the Keys enumeration. The constructor of the Key class takes as parameter an object that provides the key code, key type, content and location. You can check the information required for a Key object in the layout.js file that is exported when you create a custom keyboard layout with the Virtual Keyboard Creator tool. Here is a sample code for two Keys:


JavaScript  Copy Code

keys:
[ {
  code: 144,
  type: "special",
  content: "Num Lock",
  left: 10,
  top: 13,
  width: 40,
  height: 40
 },
 {
  code: 111,
  type: "numpad",
  content: "",
  left: 55,
  top: 13,
  width: 40,
  height: 40
 },
..........
}


Most of the time you would create Keys simply by using members of the Keys enumeration. Use autoRepeat to send the keyboard text multiple times when a key is pressed.

Special and Modifier Keys

The KeyboardState enumeration let's you (de)activate special and modifier keys. It's members are static fields.

JavaScript  Copy Code

KeyboardState.NumLock = true;

Keyboard Mode

JsKeyboard can have three modes: Default, Extended and Compact. You can change them using the layoutMode property. The modes are members of the KeyboardMode enumeration.

JavaScript  Copy Code

vKeyboard.layoutMode = KeyboardMode.Extended;

Send Key Content

You can sends key's content to focused input control programmatically by calling the Key.send method. You can use the same method to simulate that a modifier, function and num-pad key was pressed:


JavaScript  Copy Code

Keys.F12.send();


When a modifier key such as Shift or Ctrl is pressed, the keyboard does not release it immediately but waits until a regular key is pressed. If you disable autoReleaseModifierKeys, the modifier keys won't be released automatically, but the user must press them again to turn off their respective mode.

You can change the state of modifier keys with the static fields of the KeyboardState class.