timeisaparallax
Posts: 17
Joined: Thu Jan 10, 2013 3:42 am
Location: Chicago

Keyboard + Mouse

Fri Aug 15, 2014 5:33 am

I'm a graphics programmer working on some OpenGL ES 2 demos for fun / learning of OpenGL. I come from a console and windows background so I've got limited experience with deskop linux environments but plenty of C++ experience.

I'm trying to determine the best way to capture mouse and keyboard input for some minimal interactivity. I see the triangle2 sample opening /dev/input/mouse0 as a file and reading from it to get mouse data. I was aware many things are a file under the hood; is this the suggested approach for reading input in a portable from pi to pi fashion for both mouse and keyboard? A quick google shows me this API is pretty universal for linux. Is it fair to assume doing some googling about this for Debian/Linux will be consistent?


Cheers,
-Bert
Last edited by timeisaparallax on Sat Aug 16, 2014 4:09 am, edited 1 time in total.

User avatar
AndyD
Posts: 2331
Joined: Sat Jan 21, 2012 8:13 am
Location: Melbourne, Australia
Contact: Website

Re: Keyboard + Mouse

Fri Aug 15, 2014 10:12 am

Hi Bert,

I think if you are writing OpenGL ES 2 program then using /dev/input/mouse0 in the same way as hello_triangle2 example is probably the way to go.

For the keyboard you will need to use a different approach. I have some code here that allows you to poll the keyboard.

User avatar
PeterO
Posts: 5001
Joined: Sun Jul 22, 2012 4:14 pm

Re: Keyboard + Mouse

Fri Aug 15, 2014 10:23 am

AndyD wrote:Hi Bert,

I think if you are writing OpenGL ES 2 program then using /dev/input/mouse0 in the same way as hello_triangle2 example is probably the way to go.

For the keyboard you will need to use a different approach. I have some code here that allows you to poll the keyboard.
You can access the keyboard in the same way... I have code at home that uses /dev/input fpr mouse, keyboard and a CAD "3D joystick"....

I'll post example code this evening.

You can look in /usr/include/linux/input.h for info on the structres that come out of the /dev/input/ files.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5001
Joined: Sun Jul 22, 2012 4:14 pm

Re: Keyboard + Mouse

Fri Aug 15, 2014 6:27 pm

Simple example code in
http://www.peteronion.org.uk/PiProgs/input.c

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

timeisaparallax
Posts: 17
Joined: Thu Jan 10, 2013 3:42 am
Location: Chicago

Re: Keyboard + Mouse

Sat Aug 16, 2014 4:08 am

Ahh thanks Andy and Peter! This will get me moving in the right direction. Looks like I'm going to be doing some header spelunking 8-) .

At this point I'm thinking Peter's approach is the way to go. I'm curious what the different character devices at /dev/input/by-id represent. It appears I have 4 variants on the mouse (two of which match the sample regular expression):
-- usb-BTC_USB_Multimedia_Cordless_Kit-if01-event-mouse
-- usb-BTC_USB_Multimedia_Cordless_Kit-event-mouse
-- usb-BTC_USB_Multimedia_Cordless_Kit-mouse
-- usb-BTC_USB_Multimedia_Cordless_Kit-if01-mouse

while I have one keyboard that matches the respective regular expression:
-- usb-BTC_USB_Multimedia_Cordless_Kit-event-kbd

It's interesting since all I have plugged in is a single dongle for both my mouse and keyboard. I'll start spinning on this until I get something working.

Thanks!

Return to “C/C++”