Thread: How to capture raw keyboard input on Windows

  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    6

    How to capture raw keyboard input on Windows

    I have a device that acts like a HID (keyboard). I was able to capture and grab the raw input of the device on Linux. I needed to get exclusive rights to the device so that no other application could receive input from it. I accomplished this using ioctl and EVIOCGRAB

    But it doesn't compile under Windows. I have found that there is a RegisterRawInputDevices function but it doesn't seem to provide exclusive rights to the device. What could be used on Windows to achieve the same effect?


    Here is my code that works on Linux

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <unistd.h>
    #include <errno.h>
    #include <fcntl.h>
    #include <dirent.h>
    #include <linux/input.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/select.h>
    #include <sys/time.h>
    #include <termios.h>
    #include <signal.h>
    
    
    int main(int argc, char* argv[])
    {
        struct input_event ev[64];
        int fevdev = -1;
        int result = 0;
        int size = sizeof(struct input_event);
        int rd;
        int value;
        char name[256] = "Unknown";
        char *device = "/dev/input/event16";
    
    
        fevdev = open(device, O_RDONLY);
        ioctl(fevdev, EVIOCGRAB, 1);
    
    
        while (1)
        {
            read(fevdev, ev, size * 64);
            value = ev[0].value;
            printf ("code - %d \n", ev[1].code);
        }
    
    
        ioctl(fevdev, EVIOCGRAB, 0);
        close(fevdev);
    }


  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    864
    Did you google "windows exclusive access to device"?
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't capture the input
    By loongkee in forum C Programming
    Replies: 2
    Last Post: 12-30-2012, 01:37 AM
  2. How do you get keyboard handling and input from Windows API?
    By spoonlicker in forum Windows Programming
    Replies: 4
    Last Post: 01-28-2011, 01:25 AM
  3. preferred sdk for video capture under windows?
    By reanimated in forum Windows Programming
    Replies: 2
    Last Post: 03-20-2006, 06:16 PM
  4. Keyboard input in Windows NT/2K/XP native application
    By kcahcn in forum Windows Programming
    Replies: 3
    Last Post: 11-18-2002, 02:24 AM
  5. Simple keyboard capture
    By Dual-Catfish in forum Windows Programming
    Replies: 1
    Last Post: 01-25-2002, 06:11 PM

Tags for this Thread