LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2005, 07:56 AM   #1
FredKroket
LQ Newbie
 
Registered: May 2005
Posts: 5

Rep: Reputation: 0
Directly polling the keyboard under Linux


Hello,

After trying for days, I really don't know how to solve my problem:

I need to DIRECTLY POLL the keyboard under my Linux C++ (gcc) program. The program will run under ROOT priviliges in USER-space. Because I use the QT toolkit for the user-interface, the standard input is not available.

Multithreading is not an option: It is absolutely neccesary that there will only be one thread in the program, since my program will be locked into memory (mlockall) and run realtime (sched_setscheduler -> SCHED_FIFO -> highest_priority). While the program truly blocks all other processes, all I do is simple I/O instructions (inline assembly) and filling an array of values. But the problem is, I need to catch the exception that the user presses Escape.

Solutions I have tried (and thought of) so far:

- Polling the I/O port 0x60 (keyboard port), this works, but I guess it only works when I have a PS/2 keyboard connected... So USB-keyboards won't work I think, CAN ANYONE AFFIRM THIS??, since I don't have a USB-keyboard at the moment available.

- BIOS calls : not supported in Linux (nor with root-priviliges)

Anyone knows another way of directly polling the keyboard? System calls maybe? How do I do this?

Remember: My program doesn't need to be portable/compatible with other platforms. It just needs to run on Linux (preferably 2.6). (With root-priviliges)
 
Old 05-04-2005, 09:03 AM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
In the SDL library, you can use the functions SDL_GetKeyState and SDL_GetModState to get the current state of any of the keys at a specific time. Not sure if QT has something similar or not, but if it doesn't, you might still be able to use just these SDL functions.
 
Old 05-04-2005, 09:06 AM   #3
bretzeltux
LQ Newbie
 
Registered: Oct 2003
Location: Montreal, Canada
Distribution: Fedora Core 2
Posts: 23

Rep: Reputation: 15
Hi FredKroket, :-) My post is not intended to answer your question. It is my ideas of what I must do if I were in you situation:


I am not a linux/low-level programmer but if I understand your need, you have no choice but to use the BIOS's keyboard input queu addresses. <-- That means you have to write your own kernel module because those addresses ( If I remember the queu size is 15x16 bits integers ) are not accessible in user space indeed. It should not be difficult though... But if doing that you must put the CPU in real mode to access the bios array addresses ...( ouch ! )

That is true: USB keyboards are not accessed by traditional IO PORTS indeed - its USB :-)

If the BIOS is not an option because of protected mode vs real mode, then I think, still writing a custom kernel module, you are left to use the USB IO....

I would like to say that there are USB keyboard drivers modules accessible dynamicaly to be usable in user-space... I dunno tho.

good luck
Bretzel
 
Old 05-04-2005, 09:24 AM   #4
FredKroket
LQ Newbie
 
Registered: May 2005
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the replies.

I will resort to the IO 0x60 port polling method I guess, since this is the only way to poll the keyboard really fast, without using kernel/library functions at all..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
directly listening to keyboard... mukeshj Programming 3 10-07-2005 06:43 PM
NAPI in linux with kernel 2.6 for device polling wangjinyi Linux - Networking 0 09-22-2005 02:36 AM
Listening directly to the keyboard jasonM Programming 0 09-16-2005 09:58 AM
Networking Linux and Windows directly rknetsch Linux - Networking 1 06-17-2005 10:06 PM
NTP polling interval in Linux? oswald21 Linux - Networking 1 03-10-2003 03:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration