How To: Fix USB Keyboards Missing the First Keypress in Linux

I use my laptop as a desktop with an external monitor, mouse & keyboard, and found that recently the keyboard would keep missing the first character of input – and it was driving me nuts. After much googling I found a blog post over at wulftone.com that narrowed the issue down to a USB sleep problem, and described how to blacklist a USB keyboard from going into sleep mode – and it works great!

The way to fix this issue is:

1 – Find the details of your USB keyboard via the lsusb command, like this:

2 – Once you can see your keyboard, if you can’t remember which way the vendor ID and product ID go (it’s that very order), you can get the details (in this case looking at the Microsoft keyboard on bus 003, device 002) like this:

3 – Next, edit (or create if necessary) the file: /etc/udev/rules.d/91-local.rules and place the following contents into it:

So for my USB keyboard I entered:

4 – Finally, with that done you can reload the udev rules with the following and you should be all set:

As a final note, I found that this (bizarrely) didn’t work when I used the lowercase hex codes (i.e. 045e & 00dd) – I had to put them to uppercase (045E & 00DD) for it to kick in!

Sanity restored! =D

P.S. If you want to disable your first (i.e. laptop) keyboard and/or are using laptop-mode-tools then the wulftone article has you covered. So many thanks to Trevor Bortin for this fix!

Simple OpenGL Keyboard and Mouse FPS Controls

Note: This was written in January 2011 – I just never posted it, but I’d already uploaded the video to YouTube and someone asked for the code, so here it is, in all its fixed-pipeline glory ;)

Update – September 2013: I took these camera controls and wrapped them up into a Camera class in a later post which you can find here: http://r3dux.org/2012/12/a-c-camera-class-for-simple-opengl-fps-controls/. When I did this I wasn’t used to GLM (the OpenGL Mathematics library) so I just rolled my own Vec3 class – you can happily substitute glm::vec3’s if you’d like, and in fact I’d recommend it. Cheers!


I’m working on my OpenGL skills (or lack thereof) at the moment, and wanted to implement some 3D movement controls kinda of like a FPS with clipping off, so I read some chapters of the hallowed OpenGL SuperBible and did some googling, where I came across Swiftless‘ camera tutorials (Part 1, Part 2, Part 3) which gave me a really good start (Thank you, Swiftless!) on how to manipulate the ModelView matrix so we can move around a 3D scene, only it wasn’t quite perfect…

Strange things would happen like you’d look vertically downwards (i.e. directly down the negative Y axis), then you’d push forward – and yeah, you’d move “down”, but you’d also move “forward” at the same time (oh, and I’m putting things like “down” and “forward” in quotes because these concepts are all relative to your viewing orientation – not because I’m trying to be “sarcastic” or anything =P)

Anyways, I had a play with it and sorted it out after spending some time looking at the graphs for trigonometric functions and doing a little bit of off-setting and range-limiting as required. Check it out:

It actually looks quite a lot better running live than in the video due to mis-matched frame-capture rates and the like, but you get the idea =D

Full source code is available after the jump.

Cheers!

Continue reading Simple OpenGL Keyboard and Mouse FPS Controls