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
    #8  
Old Unix and Linux 09-05-2016
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 24 February 2017, 2:26 PM EST
Location: In the leftmost byte of /dev/kmem
Posts: 5,355
Thanks: 98
Thanked 1,463 Times in 1,089 Posts
Quote:
Originally Posted by wisecracker View Post
Note there were only 3 keys pressed and 1 combination of keys...
If i remember correctly the original PC keyboard was built on the Intel MCS-48 microcontroller, namely the 8042, all PC hardware still reflects that. The mcirocontroller sends so-called "make-" and "break-codes" to the main computer, which basically reflect pressing and releasing a key. Scancodes tell which key exactly was pressed (at this level is i.e. possible to separate the left from the right SHIFT key being pressed, etc.)

In the original design (but i have long since stopped to update my PC hardware knowledge) it used not only the BIOS-interrupt 09h, it also controlled the A20 gate, which was done because of a bug in the 80286 design (it couldn't get back from protected to real mode without a reboot).

I hope this helps.

bakunin
Sponsored Links
    #9  
Old Unix and Linux 09-06-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 February 2017, 3:16 PM EST
Location: Loughborough
Posts: 1,148
Thanks: 338
Thanked 299 Times in 231 Posts
Quote:
Originally Posted by bakunin View Post
If i remember correctly the original PC keyboard was built on the Intel MCS-48 microcontroller, namely the 8042, all PC hardware still reflects that. The mcirocontroller sends so-called "make-" and "break-codes" to the main computer, which basically reflect pressing and releasing a key. Scancodes tell which key exactly was pressed (at this level is i.e. possible to separate the left from the right SHIFT key being pressed, etc.)

In the original design (but i have long since stopped to update my PC hardware knowledge) it used not only the BIOS-interrupt 09h, it also controlled the A20 gate, which was done because of a bug in the 80286 design (it couldn't get back from protected to real mode without a reboot).

I hope this helps.

bakunin
See here:-
Usb_kb-io.
However we are not talking BIOS interrupts which are immaterial in this thread but HID USB protocols, disabling a USB port to re-enable it again, but, redirected to a background process. Not as easy task for the big guns let alone amateurs like me.
Sponsored Links
    #10  
Old Unix and Linux 09-18-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
Many thanks to all of you!
Now. I think you are overthinking the things.

Someone told something about a barcode scan reader and he got it -That is exactly my case.

I have my normal keyboard and also I have this barcode reader that enter text like a keyboard.

What I want is to read the text from the scanner in asynchronous mode and avoid this one mess with the real keyboard input that I want to let work as usual.

Why this thing has to be so complicated?
I don't think we have to deal with interrupts and all of that. It would need to be done in the unix way, by just reading files.
    #11  
Old Unix and Linux 09-19-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 February 2017, 3:16 PM EST
Location: Loughborough
Posts: 1,148
Thanks: 338
Thanked 299 Times in 231 Posts
Quote:
Originally Posted by SerKan View Post
I have my normal keyboard and also I have this barcode reader that enter text like a keyboard.

What I want is to read the text from the scanner in asynchronous mode and avoid this one mess with the real keyboard input that I want to let work as usual.

Why this thing has to be so complicated?
I don't think we have to deal with interrupts and all of that. It would need to be done in the unix way, by just reading files.
Erm, now I am confused.
Your OP -
Quote:
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.
- so now you don't want 2 keyboards but a USB barcode scanner instead!?
The barcode scanner will probably have its own device _name_ inside the '/dev' drawer.
You will still need to know its protocol to extract the relevant data. You will have to research that part yourself.
To see the data coming from the barcode scanner you can start by using cat /dev/barcode_scanner_devicename but this might hang or do nothing as the I/O might just be another section in the '/dev' drawer; see post #6...

As I don't have a barcode scanner to test with then my reply has to be limited.
The Following User Says Thank You to wisecracker For This Useful Post:
SerKan (09-20-2016)
Sponsored Links
    #12  
Old Unix and Linux 09-20-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
The barcode scanner works as a keyboard -That is one reason why at first I named them as 2 keyboards.

I can read the scanner/keyboard by "tail" on his /dev/input
The problem is that I want to monitor this input apart in a bakground process and not disturb the working of the normal keyboard in xorg.
Sponsored Links
    #13  
Old Unix and Linux 09-20-2016
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 24 February 2017, 3:55 PM EST
Location: Saskatchewan
Posts: 21,938
Thanks: 1,050
Thanked 4,099 Times in 3,798 Posts
I'm fairly sure you can do it, but there's a gotcha -- you'd end up processing raw key codes, not the ASCII you'd get from /dev/input.

My old tablet came with touch screen and wacom tablet screen, and those devices ended up fighting each other all the time so I had to disable one, which I did by 'grabbing' the raw mouse device so the generic /dev/mouse couldn't get it. I suspect keyboard will behave the same. I think you'll need to run the 'grabbing' part as root, perhaps not the rest of it.

Here's a slightly modified version of that code which reads data and prints to standard output:


Code:
/**
 *      grab.c
 *      grabs an evdev device to prevent it from sending events
 *      to /dev/input/mice.
 */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>

#include <linux/input.h>

#include <stdio.h>

int main(int argc, char *argv[])
{
        char buf[512];
        ssize_t bytes;
        int fd;

        if(argc != 2)
        {
                fprintf(stderr, "Syntax:  %s device-to-lock\n", argv[0]);
                return(1);
        }

        fd=open(argv[1], O_RDONLY);
        if(fd < 0)
        {
                perror("Couldn't open");
                return(1);
        }

        if(ioctl(fd, EVIOCGRAB, (void *)1))
        {
                perror("Couldn't grab");
                close(fd);
                return(1);
        }

        while((bytes = read(fd, buf, 512)) > 0)
        {
                write(STDOUT_FILENO, buf, bytes);
        }

        close(fd);
        return(0);
}


Last edited by Corona688; 09-20-2016 at 12:48 PM..
Sponsored Links
    #14  
Old Unix and Linux 09-20-2016
wisecracker's Unix or Linux Image
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 February 2017, 3:16 PM EST
Location: Loughborough
Posts: 1,148
Thanks: 338
Thanked 299 Times in 231 Posts
NO! The barcode scanner, as RudiC quoted, "acts LIKE a keyboard". It has a limited ASCII set and uses the KB event, BUT, have you found out whether it has a separate device in the '/dev/' drawer?

Not sure how you are able to read '/dev/input' as this is a directory on Ubuntu 16.04 64 bit
OS. You must be reading the 'event' which is 'event6' on said OS.

With the barcode scanner NOT plugged in do:-
ls /dev > devlist1.txt
Then plug the barcode scanner in, wait a few seconds and do:-
ls /dev > devlist2.txt
Then find the difference between the two...

If so, you could try the 'xinput' command as xinput list keyboard or something similar, assuming the binaries are in the $PATH and disable the barcode scanner and see if that still produces an output at the event handler. If not see if it can be read from its separate driver that you would have found from above. I am sure it is capable of having a separate driver for other possible uses -- BUT -- I have NOT got one so my help IS limited.

If successful you WILL still need to understand the protocol that comes from the barcode scanner, which sould closely follow a subset of that of the keyboard...

Last edited by wisecracker; 09-20-2016 at 01:45 PM.. Reason: Typos.
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 09:31 AM
Am I Connected? donmaxwelliii IP Networking 0 11-26-2009 04:35 PM
How do I know to which storage I am connected nivaspIND AIX 4 06-09-2009 03:40 AM
Connected or not connected ! !_30 Programming 3 01-21-2007 09:02 PM
How can I get Information about who is connected??? Huch AIX 3 02-23-2006 04:09 AM



All times are GMT -4. The time now is 10:40 PM.