GetCharFromKey

From GT-MP
Jump to: navigation, search
GetCharFromKey
Client-Side Function
System-users.png Client-Side Javascript.png JavaScript

Gets the char from a given key, boolean parameters can be used to simulate when ALT, CTRL or SHIFT are pressed when pressing the key.

Syntax

In Javascript
Client-Side Function

string API.getCharFromKey(uint key, bool shift, bool ctrl, bool alt);

Required Arguments

  • key: parameter input should be in uint type.
  • shift: parameter used to simulate a pressed SHIFT Key (which would cause differences on the output), input should be in bool type.
  • ctrl: parameter used to simulate a pressed CTRL Key (which would cause differences on the output), input should be in bool type.
  • alt: parameter used to simulate a pressed ALT Key (which would cause differences on the output), input should be in bool type.

NOTE: This function returns data in string type.

Usage example(s)

The example can eventually be used as a convenient template to detect certain keys in custom made input-textfields.

In Javascript
Client-Side Function

API.onKeyDown.connect(function (sender, e) {
   switch (e.KeyCode) {
      // Different cases
      case default: // Any other key that has been pressed but not detected above
         var keychar = API.getCharFromKey(e.KeyValue, e.Shift, e.Control, e.Alt);
         // Do whatever you want with "keychar"
         break;
   }
}


References