On Thu, 8 Jul 1999 16:46:40 +1000 Peter McAlpine writes: >Then when a key_down is received start a timer and >if after a preset time a key_up has not cancelled it then >do a key_held operation. I did it by polling the key at a constant rate (a good idea in any case) and using a counter in RAM. After each poll, if the key is not pressed, the poll counter gets reset to its starting value. If the key is pressed, the counter counts down by 1, unless it is already zero. When the count reaches zero, the "key held" action is performed. What is not so obvious at first is that holding a button down requires first pressing it. In some cases you need to be careful not to falsely do the "key pressed" action if the user actually is holding the key down. If the "key held" action is not a direct extension of the "key pressed" action, it is necessary to not do the "key pressed" action until the key is released (with the count not zero). They haven't made a microcontroller that can predict the future yet. If your polling rate is slower than the maximum contact bounce time (50 ms is usually a good choice), it isn't necessary to do any explicit debouncing. If you are polling fast enough that bouncing is a problem, the "key pressed" logic could be extended a little to use the counter for debouncing too. It would look for a count which is several counts less than the maximum, but not zero. That would mean that the key had been detected pressed for enough polls to count as really pressed, but not held down. ___________________________________________________________________ Get the Internet just the way you want it. Free software, free e-mail, and free Internet access for a month! Try Juno Web: http://dl.www.juno.com/dynoget/tagj.