Key Codes

Top  Previous  Next

When the kp. object is enabled (kp.enabled= 1- YES) and keys are being pressed and released, you receive the codes of these keys (key codes) along with the states they transitioned into.

So, how do you know what key code to expect from a certain key on your keypad? This topic explains.

 

Matrix keypads

On matrix keypads, key codes are formed by combining the scan line number (bits 7-4 of the key code), and the return line number (bits 3-0). Scan and return lines are numbered in the same order in which they are listed in the kp.scanlinesmapping and kp.returnlinesmapping properties.

For example, let's assume that you have a 4x4 keypad with <0> ~ <9> , <F1> ~ <F4>, <ENTER> and <CANCEL> keys. Let's further assume that you have defined your scan and return lines in the following manner:

 

Tibbo BASIC:

kp.scanlinesmapping="0,1,2,3"
kp.returnlinesmapping="28,29,30,31"

 

Here are the key codes you will get. Notice how key codes in their hex representation reflect the number of the scan line (high digit) and return line (low digit):

 

kp_keypad_example

 

Binary Keypads

On binary keypads, your TiOS system is separated from the keypad by the scanning circuit of the keypad. This circuit typically comprises a small microcontroller.

How that microcontroller assigns a key code to each key is the decision made by the designers of this microcontroller's firmware. There are no rules here and all you can do is test the keypad and find out what key codes it generates, beginning with the idle code that is present on the interface lines when no keys are pressed.