GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.5k stars 286 forks source link

Unclear how to (reliably) process key/window events #292

Open matthijskooijman opened 4 years ago

matthijskooijman commented 4 years ago

I've tried using CImgDisplay for showing a small window and processing key events, which is pretty much exactly what I was looking for, nice!

However, I'm a bit confused about how to handle (key) events reliably. What I want to do is simply process all key events in the order that they come in. Looking at key events, I see two relevant methods for this:

Say that there are two events in the queue. There's a few problems:

Looking at the examples, most of them seem to just look at the most recent key event and after processing it, clear the event queue (potentially missing key events when they occur quickly). For those examples, there seems to be no point in keeping a queue of 128 positions, just one would have done the same.

So I'm wondering: How was all this intended? Am I missing something here?

dtschump commented 4 years ago

Hello Matthijs,

Indeed, we can say that the way CImgDisplay processes key events is 'rudimentary'. That's because I've never really needed to make complicated key detections so far with CImg. TBH, I almost never used the CImgDisplay::keys() and CImgDisplay::released_keys() methods, but rather the individual CImgDisplay::is_keyESC() methods to check if a particular key is pressed or not, which I found more convenient (but if they are not tested quick enough, there is also a chance we miss some key press with those too). All your points are then valid. The key detection system should be probably improved.

matthijskooijman commented 4 years ago

Ok, good to know. For now, I'll just roll with this (it's just a rough tool for internal use only that I'm working on), maybe I'll come back to this if I run into problems.

but rather the individual CImgDisplay::is_keyESC() methods to check if a particular key is pressed or not, which I found more convenient (but if they are not tested quick enough, there is also a chance we miss some key press with those too).

Right, my bigger worry would be that you end up processing a keystroke more than once, though.