views:

140

answers:

1

We are writing an ExtJS application that relies in large measure on trapping a users keystrokes. However I believe I have discovered a "timing issue" in that, when the keys are pressed too rapidly, unexpected behavior manifests, specifically in our case, duplicate entries get added to an array being buffered in memory.

I have an idea for a solution but am seeking input as to pitfalls to my idea, and other possible solutions. In essence my idea would be, instead of handling each keypress directly, adding the keypress to a stack, and then invoking a function/method that processes the stack. That function will always pop one item off the stack for starters. But when it is done doing so, it will check as to whether the stack has since been appended, and if so, process that entry (or entries).

+2  A: 

A stack would give you last-in-first-out (LIFO) where you would more than likely want to utilize a queue for first-in-first-out (FIFO) as you would want to be dequeuing key characters that first came on the stack. So in theory you would want to use enqueue/dequeue as opposed to push/pop to process keys in the correct order they came in.

cballou
Even though you accepted this answer because it corrected the solution as you described it, I'd still be curious to know more about why you are having this issue in the first place. I've implemented real-time keystroke processing with Ext without any issues or the need for queuing keystrokes, so I suspect there may be some underlying issue that you'd still want to fix in your own code.
bmoeskau