LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-17-2006, 05:35 AM   #1
duncanbojangles
Member
 
Registered: Jul 2003
Posts: 34

Rep: Reputation: 15
Generating 'fake' keyboard keypresses


I'm writing a userspace driver for the Belkin nostromo n52 Speedpad device that will convert multiple keypresses on the device into one keypress that looks like it came from the real keyboard. The device currently acts like a standard USB HID keyboard, but mapped like the left side of a keyboard. I've managed so far to grab the USB device, detach the current driver that's handling it and read all the necessary data. The only part I'm stuck on is generating the appropriate keypress like it came from a standard USB keyboard. I need to make sure this works in the console, too, and not just in X, which would have been easy.

I've thought of hacking the usbkbd driver source code to only recognize the Speedpad's USB Vendor ID and Product ID and put my own keypress handling code in there, but that seemed like more work than it had to be, and I already wrote most of the code using libusb, which couldn't be used in a driver module.

I just need a simple way to push keypress and keyrelease events to the kernel. I've looked at linux/input.h but that's only for kernel and module code, and I've looked at linux/uinput.h but can't seem to decipher its inner workings.

Something like a pipe to a /dev file would be the easiest thing, but I'm unsure if there's even a /dev/ file available for the keyboard that allows that kind of access.

Any information for sending fake keypresses would be greatly appreciated, since I've googled 'till my eyes could stand it no longer and found lots of almost helpful stuff.
 
Old 03-17-2006, 10:13 PM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 57
Maybe libfakekey from here might help?
 
Old 03-18-2006, 03:39 PM   #3
duncanbojangles
Member
 
Registered: Jul 2003
Posts: 34

Original Poster
Rep: Reputation: 15
A good library, no doubt, but doesn't exactly match my needs since it depends on an X server running. Thanks for pointing it out, though, I'm sure it may be useful at one point in time.
 
Old 03-18-2006, 10:50 PM   #4
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
I have watched this thread with fascination, as this question is very interesting.

I'm scared of blowing up my server[1], plus I don't have a Linux computer with a keyboard, however:
Can you write stuff to /dev/console? Do you have a device like /dev/kbd0?

I've never fully grokked the reasons for using userspace and kernelspace, but why are you making a userspace driver?

-pcweirdo.

[1] The server runs Linux but it doesn't have a power switch, screen or keyboard, so if it goes down it's a bitch to restart.
 
Old 03-21-2006, 02:23 AM   #5
duncanbojangles
Member
 
Registered: Jul 2003
Posts: 34

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pcweirdo
I have watched this thread with fascination, as this question is very interesting.
It mustn't be that interesting, since not too many people seem to have done it before!
Quote:
Originally Posted by pcweirdo
Can you write stuff to /dev/console? Do you have a device like /dev/kbd0?
I haven't been able to shuffle data to any /dev file and get a reaction. I keep getting the response "/dev/kbd: No such device", "/dev/input/keyboard: No such device", etc.
Quote:
Originally Posted by pcweirdo
I've never fully grokked the reasons for using userspace and kernelspace, but why are you making a userspace driver?
There's just too much to worry about when writing a kernel module! If it crashes, my whole dang system will probably go down, and module programming just isn't fun. You can't use any cool libraries like libusb and you have to be really careful with memory allocation. Libusb makes talking to the device so easy it's silly, and I just don't wanna write that much C code anymore.
 
Old 03-21-2006, 06:50 AM   #6
pcweirdo
Member
 
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58

Rep: Reputation: 15
You have a way of good thinking there, buddy. Sorry I couldn't be of more help.

-pcweirdo.
 
Old 03-25-2006, 03:39 AM   #7
duncanbojangles
Member
 
Registered: Jul 2003
Posts: 34

Original Poster
Rep: Reputation: 15
Well, I still haven't found anything that quite suits my needs, so I went ahead and made sure I could push keypresses to the X server. It's actually quite simple, but requires too much "setting up" for my liking. Since I need access to the USB bus, I run the userspace driver as root, but to push keypresses to the X server, I need to make sure X accepts stuff from root, so I have to run "xhost +localhost" once before running the driver. The device is USB, so it should just be plug and play!

What I did instead is hack up the code that accompanied the "Writing an Input Module" tutorial located at http://www.linux.it/~rubini/docs/input/input.html to accept input from a /dev file and push it to the input subsytsem of the kernel as actual keyboard keypresses. Not exactly what I was looking for, but closer than my current situation. Now I can concentrate on the userspace driver, and once it is complete, I will rewrite it as a kernelspace driver.

If anyone would like the code I have so far, just reply to this post and I'll send it your way. No private messages, please, as I forget to check them.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ps/2 keyboard -> usb connector generating spurious keystrokes on suse 9.3 Thespian Linux - Hardware 6 03-13-2006 05:41 PM
Mapping keypresses to buttonpresses dhow Linux - Software 1 10-26-2004 07:39 PM
running "fake" display with keyboard input thebover Slackware 9 09-15-2004 01:27 AM
Weird - Mouse button events for keyboard keypresses? pavgust Linux - Hardware 1 06-17-2004 05:44 AM
fake out netcraft.com chrisknight Linux - General 8 03-13-2004 08:53 PM

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

All times are GMT -5. The time now is 01:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration