Unix/Linux Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Read 1 of 2 keyboards connected

Programming


Tags
disable, keyboard, programming, xorg

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-03-2016
SerKan SerKan is offline
Registered User
 
Join Date: Sep 2016
Last Activity: 23 September 2016, 5:07 PM EDT
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Linux Read 1 of 2 keyboards connected

Hi all experts in linux and programming!

I want to make work the following setup:
2 usb keyboards connected to a normal x86
One keyboard working as usual in xorg, but I need that the other one doesn't send anything to xorg but instead I want to process its keystrokes with some kind of background process.

How can it be done? Linux
Sponsored Links
    #2  
Old Unix and Linux 09-04-2016
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 30 March 2017, 8:13 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 5,388
Thanks: 98
Thanked 1,481 Times in 1,101 Posts
Quote:
Originally Posted by SerKan View Post
2 usb keyboards connected to a normal x86
One keyboard working as usual in xorg, but I need that the other one doesn't send anything to xorg but instead I want to process its keystrokes with some kind of background process.
First a bit of theory: you communicate with a UNIX system by using a "tty": a "terminal" consisting of a keyboard and a screen, usually connected via a serial line.

If you connect to a UNIX system over a network you use a so-called "terminal emulator program" (many times "xterm", but that is not the only one) to emulate such a terminal and its serial connection is emulated via the network connection.

There is a special form of a tty, which is called console. This is not connected via the standard serial line but directly attached to the computer. Perhaps the local screen attached to your VGA-card and the (first) keyboard form this console.

Now, after that much theory, to your specific question: this might work, but not necessarily with a USB-attached keyboard and definitely not with a background process. Background processes are part of a process hierarchy, headed by some foreground process: this is usually the shell from which you initiated the background process, typically by issuing the command:


Code:
$ /path/to/command -someoptions &

Since the shell you typed that in was already connected to some tty (the one which keyboard you used to type it, probably the console) the background process inherited this connection. You can cut it off from this (by using the nohup command) but per default itis attached to the one you used to call it. Furthermore, a single USB-attached keyboard is not a terminal.

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
SerKan (09-18-2016)
Sponsored Links
    #3  
Old Unix and Linux 09-05-2016
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 30 March 2017, 8:39 AM EDT
Location: Aachen, Germany
Posts: 10,567
Thanks: 258
Thanked 3,236 Times in 2,983 Posts
There are devices such as bar code readers that can be connected to act like a keyboard. So - in principle, I guess your request should be doable, while I don't have a solution at hand.
Does it make sense to connect a keyboard without a screen enabling people control over what they typed in?
    #4  
Old Unix and Linux 09-05-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 29 March 2017, 5:32 AM EDT
Location: Loughborough
Posts: 1,176
Thanks: 353
Thanked 312 Times in 242 Posts
Before attempting ANYTHING that hits the hardware hard, read up on any protocols required for the USB ports, plus how they work and this includes the keyboard and mouse for those ports too. KB and mouse use USB version 1.1, [1.0?], minimum and do not require I/O speeds greater than about 1.5Mbs data rate.

In Linux flavours, or at least most, there are __accessable__ devices that can be read from and/or written to. I have no idea if this is true of professional UNIX tools however. The protocol for the keyboards being sent and received can be read easily using basic code in differing languages but not necessarily sync'd at all. The data being sent by the KB has many bytes in it in binary form; the same goes for the pointing device,(mouse).

Writing to a USB port via one of these devices is not the same animal however.

Unless you have at least studied how this/these __serial__ interfaces work be careful as they are __effectively__ in __parallel__. As bakunin has implied these could be allocated tty[?] device names in the UNIX domain but can be COM[?], usually COM1 and COM2 for KB and mouse respectively, in the Windows domain, but I have no idea what they are in the Apple OSX !0.7.x and above domain, perhaps also tty[?]. The Linux domains could be special devices and/or tty[?].

IMO it is certainly not an easy task for a novice to intercept a second KB's I/O and redirect from its main duty as user input on any machine in question.

(I would like to be proven wrong however.)

Bazza.
Sponsored Links
    #5  
Old Unix and Linux 09-05-2016
Juha Nurmela Juha Nurmela is offline
Registered User
 
Join Date: Sep 2016
Last Activity: 11 October 2016, 2:01 PM EDT
Location: Sweden
Posts: 27
Thanks: 1
Thanked 8 Times in 8 Posts
I can't say anything about Linux, but in FreeBSD it would not be really hard.

You just have to tell devd (and possibly Xorg) to ignore that specific keyboard. If can do that, you are free to read /dev/ukbd0 (or ukbd1) as you please. What you get from there might be ascii or scancodes, or you might be able to choose.

It should be similar in Linux, devd is called udev there, I think.

Juha
The Following User Says Thank You to Juha Nurmela For This Useful Post:
SerKan (09-18-2016)
Sponsored Links
    #6  
Old Unix and Linux 09-05-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 29 March 2017, 5:32 AM EDT
Location: Loughborough
Posts: 1,176
Thanks: 353
Thanked 312 Times in 242 Posts
Here is a snapshot of reading KB event6 in Ubuntu 16.04 64 bit...
It is in /dev/input/ ...
As I quoted in most Linux flavours reading is easy, understanding the protocol is NOT!
As you can see with this snapshot of the 'Ubuntu Terminal', to run it from the '/dev/input/' directory requires 'sudo'...
sudo cat event6
Note there were only 3 keys pressed and 1 combination of keys...
Now see how difficult it is to monitor any KB knowing its device, just think how difficult it is if you have disabled said KB and required data from it.
Attached Thumbnails
Read 1 of 2 keyboards connected-ubuntu-16-04-64-jpg  
Sponsored Links
    #7  
Old Unix and Linux 09-05-2016
Juha Nurmela Juha Nurmela is offline
Registered User
 
Join Date: Sep 2016
Last Activity: 11 October 2016, 2:01 PM EDT
Location: Sweden
Posts: 27
Thanks: 1
Thanked 8 Times in 8 Posts
Okay, I was assuming too much.

Juha
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Connected to IANA anyway, why? 1in10 IP Networking 2 08-21-2016 08:31 AM
Am I Connected? donmaxwelliii IP Networking 0 11-26-2009 03:35 PM
How do I know to which storage I am connected nivaspIND AIX 4 06-09-2009 02:40 AM
Connected or not connected ! !_30 Programming 3 01-21-2007 08:02 PM
How can I get Information about who is connected??? Huch AIX 3 02-23-2006 03:09 AM



All times are GMT -4. The time now is 08:49 AM.