Linux Today: Linux News On Internet Time.

More on LinuxToday

Linux Journal: Mouse Programming with libgpm

Jan 25, 2002, 10:04 (0 Talkback[s])
(Other stories by Pradeep Padala)

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

"When I was first introduced to programming (back with DOS), I used to add mouse support to my applications to impress my teachers. Programming the mouse largely consisted of putting the right values in the registers (like 0x00 in the ax register to reset the mouse) and calling the interrupt service routine with int86 ( a function provided by Turbo C to access interrupt service routines). So when I put my hands on a Linux box, I looked for some thing similar. I soon found out that only root can access hardware registers directly. But there's an elegant way to handle this.

Welcome to the world of gpm and its client libraries. When I started searching for useful information about how to program mouses in UNIX (Linux in particular), I found some C code that let people access and program the mouse through /dev/mouse . But I was overwhelmed by the intricacies of handling different mice and was forced to look for other avenues. After pouring over the man pages of gpm, I learned to program the mouse with ease, and in no time, I was playing withmy mouse. I was quite impressed by the extent of services these libraries provided and was compelled to explore them further.

It is quite easy to program with gpm and write portable and robust applications with a few lines of code. In this article, I will explain the concepts involved in programming the mouse with simple but effective examples. To compile them you will need libgpm, which can be obtained from To compile the program successfully, you will have to add the -lgpm flag:"

Complete Story