The Linux keyboard driver

Our Kernel Korner series continues with an article describing the linux Keyboard driver. This artilce is not for “Kernel Hackers” only—in fact, it will be most useful to those who wish to use their own keyboard to its fullest potential, and those who want to write programs to take advantage of the many features in the Linux keyboard driver.
Using loadkeys

Use loadkeys to change the code produced by the BackSpace key from Delete to BackSpace:


% loadkeys
keycode 14 = BackSpace

Assign the string “emacs\n” to the function key F12, and “rm *~\n” to Shift-F12 (the keycode 88 was found using showkey; the F66 is a random unused function key symbol):


% loadkeys
 keycode 88 = F12
 shift keycode 88 = F66
 string F12 = "emacs\n"
 string F66 = "rm *~\n"

Create the compose combination that will compose | and S into $:


% loadkeys
 compose '|' 'S' to '$'
 compose 'S' '|' to '$'

Reset to some default state:


% loadkeys -d
Sequel

After the above handling, the obtained character(s) are put in the raw tty queue. Depending on the mode of the tty, they will be processed and transferred to the cooked tty queue. (Don't confuse raw mode as stty knows it, with the raw scancode mode discussed above.) Finally, the application will get them when it does getchar();.

Andries Brouwer, aeb@cwi.nl, has used Unix for various mathematical, linguistic, and playful purposes the past 20 years or so. He might be known to some for the first net release of hack.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

how to test power and ptt keys??

lakshmi's picture

Hai i want to test power and ptt keys. I am using evtest to test my keys on the keypad. But my driver wont generate any interrupt for power and ptt keys so how to test these keys??

general awareness

Anonymous's picture

general awareness

Getting keyboard scancodes

email's picture

The article is confused.
Please write a simple non-blocking function.

This can be the prototype:

bool keypressed( int& scancode );

bye
miro

linux keypad driver

Anonymous's picture

the scancode related information are good

Re : Kernel Korner: The Linux keyboard driver

Anonymous's picture

Good One !! But really missing the source code as example.

Re: Kernel Korner: The Linux keyboard driver

Anonymous's picture

It's better to explain with a practical keyboard source code.

Re: Kernel Korner: The Linux keyboard driver

Anonymous's picture

can u pls send the c code for keyboard device driver

need c code of keyboard driver

G Abbas's picture

i will be greatful if someone help me. i need c code fo generic keyboard driver.

Can you please send me

Anonymous's picture

Can you please send me source code of a generic keyboard driver?

Need it for Windows/Dos environment

Anonymous's picture

Hi

I need to access certain keys on a Pentuim PC keyboard using ISO. But ISO just specifies the H and no C files and it only gives you the CRT device not the keyboard-subdevice of the CRT.

So I've decided to do a search for keyboard-drivers. And now I want the complete c code for a keyboard driver, please?

Re: Kernel Korner: The Linux keyboard driver

Anonymous's picture

not a practical example... too confuse

Yes you are right

Kenson Goo's picture

Linux needs to simplify everything so that our grandparents can use the system easily. I bet my grandparents would prefer Microsoft keyboard like http://www.compkeyboard.com/archives/microsoft-natural-ergonomic-keyboar...

than a Linux system with 4 pages of tutorial on keyboard

Dude, your an idiot. Your

Anonymous's picture

Dude, your an idiot. Your grandparents are very unlikely to be writing keyboard drivers for Linux or Windows.

Grandparents

Anonymous's picture

Oh, yeah? Well, my grandparents are awesome like that: 'Cept they write drivers for *nix only!

key state

Anonymous's picture

getchar() is a blocking call and when you press a button the corresponding character is output to the terminal. Would if all I wanted was the state of any given key at any given time? Doing this on PS2 Linux is quite easy with the js0 device for composing a bit-feild containing the state of each controller button this frame. Is their a non-blocking, non-printing way to obtain the key state of any given key?

Source code for keyboard.c in on your computer

Tim Crawford's picture

If you install the kernel source code you can find the source
code in /usr/src/linux/drivers/char/keyboard.c

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix