Re: Keeping state with key press and key release events



On 03/19/2012 06:54 PM, Arvind Kumar wrote:
I am not on the list but saw your message and read the thread.

However, the approach I was hoping for, i.e. simply checking the
current "reality" state of a key (whether it is actually pressed down
or not) sounds more convenient. If anyone could tell me how to do
that, I would be grateful.

Why don't you just set the state by maintaining a boolean variable and
setting it in the key press event and unsetting it in the key release event?

That flag should get you where you want. Am I wrong?

-a

I just implemented that today in my program, though I used bit flags so
I could pack a few keys into one int.

This seems to work well enough, though there have been some challenges:
in particular, there is the matter of timing. Users expect that when
they "tap" a key, that the associated action will only complete once,
whereas in reality the time between key press and key release will last
through at least three or four calls of the timing function.

I imagine that there are a few different ways of dealing with this, but
my approach was to reduce the amount of times per second that I actually
check the key states, through the use of a counter variable. It then
takes a bit of tweaking to figure out a good frequency.

-- 
frigidcode.com
indicium.us



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]