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

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState