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-05-2014, 09:13 PM   #1
random110
LQ Newbie
 
Registered: Jan 2014
Posts: 20

Rep: Reputation: Disabled
Trying to hack Xorg with C++ to work with a custom keyboard.


I wasn't sure exactly which board to post this in, but I guess for starters you would have to know some code to understand the problem so I'll try here first, and for anyone who can help thanks a million in advance!

I don't think you'll find this to be an elementary question. The situation is that I am installing some software to run on a custom build factory machine. It's sort of an embedded system. I installed minimal debian and hacked it down to less than 1 Gb to fit on the limited drive space, and we have a little 800 x 600 LCD attached to it. It's all working well, and a very interesting project.

Here's the catch. The "keyboard" (if you can call it that) or "keypad" is kind of like a big cellphone keypad from before the "smart phone, touch screen, etc" days, kind of like "bubble buttons" that make a pop/click when you hit them. It has a sort of flat bus cable that connects directly to the main board, but it is PS/2 standard (like the old circle plug-in mouse and keyboards standard). And seems to work OK with some i8042 params sent to the boot sequence.

So far so good, right? So here's the heart of the problem. The keyboard seems to work fine in a non-GUI tty, but when I get into X, I want to bang my head in frustration. The keys keep repeating, so that one tap of a '1' will go 11111111111111111111... until you hit enter or shut the machine off or something. In order to tame the beast down a bit I did

Code:
$ xset r off
That stops keyboard repeats... so now I can hit the '1' and just get a single '1' as expected... but wait it only works ONCE now...? So if I hit '1' it will display a 1 or do the function that 1 calls, but after having done it once, it won't do it again until rebooting.

Some investigation and after learning everything there is to know about xorg's relation with keyboards, I come to find that it's actually kind of the keypad's fault.

Here's where you might need to be a coder to understand. Each press of this strange keypad's keys will send a "key press" signal, but it does not send a "key release" signal when you let off the key. Because it is a custom, odd little keypad and that's just how it is. If you don't know, most systems and coding methods expect each key to have both a "key down" and "key up" signal to be sent. Otherwise you can't know if the key press is complete. So now we can see why this keypad was sending 11111111111111.... instead of just 1 after one tap.... Xorg sees that the key was pressed down, but nothing told it that my finger left, so it assumes I'm just holding it down infinitely.

However...

It works just fine in a non-GUI tty (bang.head.on.desk.repeat.)

So then I spent a day or two all over the web learning about how to send a key signal to Xorg and tried customizing my application to send a release signal for each key press signal to reset the keys after strike. I've been through all of these...

Code:
$ xset
$ xinput
$ xkbset
$ ...
And nothing seems to help.

I also tried to see if there was someway I could just reset the whole keypad after each key stroke... no avail.

Mind you it's supposed to be a regular old PS/2 keyboard, and I can confirm that it is in fact sending regular standard keypress signals... just not releasing them ever.

Does anyone have any advice for this?

Much appreciated if you do. Hope you enjoyed the reading otherwise! and feel free to ask if you have any questions.
 
Old 05-06-2014, 06:39 PM   #2
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 518
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
I loved this post! Very interesting question you have there, and your project seems interesting too!

I did some research, and maybe an easy way might be to hack this program to receive the input keypress and send key release events back: http://www.semicomplete.com/projects.../xdotool.xhtml

By the way, do you plan to use a window manager? Maybe that can be modded to do this sort of stuff too.

At first I was going to suggest modding the keyboard input driver, but I think this might be the easier way to go.
 
Old 05-08-2014, 11:12 PM   #3
random110
LQ Newbie
 
Registered: Jan 2014
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by DJ Shaji View Post
I loved this post! Very interesting question you have there, and your project seems interesting too!

I did some research, and maybe an easy way might be to hack this program to receive the input keypress and send key release events back: http://www.semicomplete.com/projects.../xdotool.xhtml

By the way, do you plan to use a window manager? Maybe that can be modded to do this sort of stuff too.

At first I was going to suggest modding the keyboard input driver, but I think this might be the easier way to go.
I'm glad you liked the post! I thought it would do better to explain the background and make it an interesting read! and sorry for my late reply.

Remember I need to keep the system at under 1 Gb, a very bare bones install, and so I have only installed openbox. I don't know if a gdm comes with that by default to be honest, but I can say that I did not implicitly install a window manager at this time.

I did actually try xdotool, as well as various other tools that do the same job! But it seems as though the odds are out to get me, no matter what I try this time! There was one scenario where I set up xdotool to find the current window of the application, switch to that window, then apply the key strokes I told it to do. I watched it before my very eyes and actually thought that was both impressive and interesting I'll have to remember that trick for later. However.... it still didn't fix my problem. The key is still stuck in the down position, according to Xserver, for the keyboard in question... and so that leads me to think again... why???

So now with this experiment we can see that xdotool does in fact apply key presses, AND it has the ability to specifically send "key up" events for specific keys, and to the specific window in question... BUT, it does not effect the "STATE" of the keyboard in question. AHA! This must mean that the key press events being sent by xdotool must be specific to a "particular" keyboard event... as if there was a second keyboard plugged in, and the keyboard event being sent is just being emulated through that pseudo keyboard. Just a moment please... (bang.head.on.desk.repeat).

So then I went on another magical journey to see if I could specify the keyboard being used to send the event. This led me to some reading which seems to suggest that these utility's key events are sending the events through the "core keyboard", as is default to the system, and/or specified in xorg.conf. Lucky me, I have a well configured xorg.conf to make sure things work stable on this machine! But I have "temporarily" lost all will to continue this endeavor! Mostly because I have a feeling that the xorg.conf is going to lead me to some other new surprises which I won't articulate just now.

So after a weekend break I will pick up where I left off, which is trying to figure out why the emulated keyboard events are not interacting via the keyboard in question... or rather if that is even possible... or rather if xorg's core "system event" is what needs to be triggered and how to do that...?!?!?
 
Old 05-10-2014, 03:34 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Perhaps you could skip the keypad and (if you have enough space) install an on-screen keyboard. Some versions can, I think, be set to work like smartphone keyboards, and only "pop up" when you select an input text box.
 
Old 05-16-2014, 06:30 PM   #5
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Rep: Reputation: 29
If you are willing to give it a shot, x.org has a tutorial on making Xorg input drivers. I followed it before for a touchpad device I was working with and its pretty simple to follow.
You can find it here: http://www.x.org/wiki/Development/Do...orgInputHOWTO/
Good luck
 
  


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
3 keyboard layouts in xorg.conf doesn't work VMM Linux - Newbie 3 11-10-2009 05:43 PM
Hebrew PS/2 Keyboard to work with Slackware 12.1 /etc/X11/xorg.conf ivri Slackware 11 11-09-2009 02:33 AM
[SOLVED] Cross-LFS with custom kernel: Keyboard does not work! timmytycoon Linux - Hardware 1 06-27-2009 11:35 AM
Removing custom built Xorg to install Etch's Xorg kushalkoolwal Debian 4 05-30-2007 01:50 AM
Can't get DIN5 keyboard to work in XFree86 / Xorg CoolAJ86 Linux - Hardware 0 02-11-2005 07:36 PM

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

All times are GMT -5. The time now is 07:49 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