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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-17-2006, 04:35 AM
|
#1
|
Member
Registered: Jul 2003
Posts: 34
Rep:
|
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.
|
|
|
03-17-2006, 09:13 PM
|
#2
|
Senior Member
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545
Rep:
|
Maybe libfakekey from here might help?
|
|
|
03-18-2006, 02:39 PM
|
#3
|
Member
Registered: Jul 2003
Posts: 34
Original Poster
Rep:
|
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.
|
|
|
03-18-2006, 09:50 PM
|
#4
|
Member
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58
Rep:
|
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.
|
|
|
03-21-2006, 01:23 AM
|
#5
|
Member
Registered: Jul 2003
Posts: 34
Original Poster
Rep:
|
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.
|
|
|
03-21-2006, 05:50 AM
|
#6
|
Member
Registered: Oct 2004
Location: Melbourne-ish, Australia
Distribution: Gentoo, Windows XP Pro
Posts: 58
Rep:
|
You have a way of good thinking there, buddy. Sorry I couldn't be of more help.
-pcweirdo.
|
|
|
03-25-2006, 02:39 AM
|
#7
|
Member
Registered: Jul 2003
Posts: 34
Original Poster
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 12:24 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|