Sponsored Content
Top Forums Programming Read 1 of 2 keyboards connected Post 302981845 by Corona688 on Tuesday 20th of September 2016 11:40:57 AM
Old 09-20-2016
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..
 

10 More Discussions You Might Find Interesting

1. AIX

How can I get Information about who is connected???

Hello, I'm new here and I come from Germany. At our AIX-ORACLE-System someone has deleted one important file and we'd like to find out who did this, next time. Is there any command to find out who is connected? I'm not trying to find out if it's root, etc., I'd like to get the DNS-Name or... (3 Replies)
Discussion started by: Huch
3 Replies

2. Programming

Connected or not connected !

Hello ! I've got a question . I really don't het this point. Let's supose that I have a client connected to a server. I want the server IMEDIATLY know if the client is diconnected . How can I realize this ? :mad: Amd I'm just curios about one thing. I have a server and multiple clients... (3 Replies)
Discussion started by: !_30
3 Replies

3. IP Networking

check whether connected to network

hi... can anyone pls suggest a few methods to check whether a computer is connected to any network, using the terminal, not GUI. thanks eskay (1 Reply)
Discussion started by: eskay_karthik
1 Replies

4. UNIX for Advanced & Expert Users

linux connected to as400

we have a as400 5rev4 and want to use a rhel server to use as a file server. We exported a drive on the rhel box and then mounted it on the as400. We can see the top directory in our mounted as400 directory but when we attempt access subdirectories we get a no matching object error. When we open... (2 Replies)
Discussion started by: javagair
2 Replies

5. AIX

How do I know to which storage I am connected

Hello everyone. We have a environment where we have DS8K storage and ES800 storage, the way to check to which storage the box is connected is using the LUN ID I get frm " pcmpath query device " command. for ex: 75CXX - DS8K storage 26860 - ES 800 Storage I was told to check... (4 Replies)
Discussion started by: nivaspIND
4 Replies

6. IP Networking

Am I Connected?

Be Gentle folks, I am a baby OpenSuSe 11.2 user :-) In windows Vista, there is a world in the systray when you are Internet connected and not just local. I have searched all over for a .RPM for the Network Manager or another packeg in Suse that can show me the same thing or something close. ... (0 Replies)
Discussion started by: donmaxwelliii
0 Replies

7. UNIX for Dummies Questions & Answers

Non Internet connected distribution

Hi all I've been a Debian user since solidly since about 1997 so I'm fairly experienced Linux user as a whole but unfortunately the monoculture has hit be hard recently. I'm working off a Laptop a lot of the time which spends up to 2-4 weeks without an Internet connection. A few weeks ago it... (1 Reply)
Discussion started by: pointyhat
1 Replies

8. UNIX for Dummies Questions & Answers

Ftp showing connected only

hi, good morning. Anyone can help me out. A trying to ftp from server A to server B. from server A to B its working fine but from server B to A, its only showing connected only: finap7 #ftp 10.10.10.210 Connected to 10.10.10.210. I refresh the inetd but nothing is happening. Please... (1 Reply)
Discussion started by: kamaldev
1 Replies

9. OS X (Apple)

How to see connected macs through terminal?

Been a while since I've been here; I have my iMac and MBpro connected via firewire, and they can see each other when I open the finder windows. But I'd like to be able to 'see' each computer on the other via the terminal application; and I can't see them right now. I can transfer files via the... (0 Replies)
Discussion started by: Straitsfan
0 Replies

10. IP Networking

Connected to IANA anyway, why?

May someone can answer this. Anytime I ignite my laptop to go online I see via etherape that I am connected to IANA as shown below. Is my provider redirecting me there, the cable under the sea, what is the reason for this? This happened with a pretty normal desktop PC, as well with my ancient... (2 Replies)
Discussion started by: 1in10
2 Replies
grab(3) 						User Contributed Perl Documentation						   grab(3)

NAME
grab - Confine pointer and keyboard events to a window sub-tree SYNOPSIS
$widget->grab $widget->grabOption DESCRIPTION
This set of methods implement simple pointer and keyboard grabs for Tk. Tk's grabs are different than the grabs described in the Xlib documentation. When a grab is set for a particular window, Tk restricts all pointer events to the grab window and its descendants in Tk's window hierarchy. Whenever the pointer is within the grab window's subtree, the pointer will behave exactly the same as if there had been no grab at all and all events will be reported in the normal fashion. When the pointer is outside $widget's tree, button presses and releases and mouse motion events are reported to $widget, and window entry and window exit events are ignored. The grab subtree ``owns'' the pointer: windows outside the grab subtree will be visible on the screen but they will be insensitive until the grab is released. The tree of windows underneath the grab window can include top-level windows, in which case all of those top-level windows and their descendants will continue to receive mouse events during the grab. Two forms of grabs are possible: local and global. A local grab affects only the grabbing application: events will be reported to other applications as if the grab had never occurred. Grabs are local by default. A global grab locks out all applications on the screen, so that only the given subtree of the grabbing application will be sensitive to pointer events (mouse button presses, mouse button releases, pointer motions, window entries, and window exits). During global grabs the window manager will not receive pointer events either. During local grabs, keyboard events (key presses and key releases) are delivered as usual: the window manager controls which application receives keyboard events, and if they are sent to any window in the grabbing application then they are redirected to the focus window. During a global grab Tk grabs the keyboard so that all keyboard events are always sent to the grabbing application. The focus method is still used to determine which window in the application receives the keyboard events. The keyboard grab is released when the grab is released. Grabs apply to particular displays. If an application has windows on multiple displays then it can establish a separate grab on each display. The grab on a particular display affects only the windows on that display. It is possible for different applications on a single display to have simultaneous local grabs, but only one application can have a global grab on a given display at once. The grab methods take any of the following forms: $widget->grabCurrent Returns the current grab window in this application for $widget's display, or an empty string if there is no such window. $widget->grabs Returns a list whose elements are all of the windows grabbed by this application for all displays, or an empty string if the application has no grabs. Not implemented yet! $widget->grabRelease Releases the grab on $widget if there is one, otherwise does nothing. Returns an empty string. $widget->grab Sets a local grab on $widget. If a grab was already in effect for this application on $widget's display then it is automatically released. If there is already a local grab on $widget, then the command does nothing. Returns an empty string. $widget->grabGlobal Sets a global grab on $widget. If a grab was already in effect for this application on $widget's display then it is automatically released. If there is already a global grab on $widget, then the command does nothing. Returns an empty string. $widget->grabStatus Returns none if no grab is currently set on $widget, local if a local grab is set on $widget, and global if a global grab is set. BUGS
It took an incredibly complex and gross implementation to produce the simple grab effect described above. Given the current implementation, it isn't safe for applications to use the Xlib grab facilities at all except through the Tk grab procedures. If applications try to manipulate X's grab mechanisms directly, things will probably break. If a single process is managing several different Tk applications, only one of those applications can have a local grab for a given display at any given time. If the applications are in different processes, this restriction doesn't exist. KEYWORDS
grab, keyboard events, pointer events, window perl v5.16.3 2014-06-10 grab(3)
All times are GMT -4. The time now is 06:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy