Simple keypress question

Hello everyone. I have a simple question that's been keeping me stumped lately:

How is it possible to invalidate a keyread while the previous keyevent is still in effect?

Example of problem: Someone presses 'a' on the keyboard 7 times. In effect, this would mean that the key-handling event will be carried out 7 times in a row. If these key-handling events take a while, the program will be continuing these events for a long period of time. What I would like to do is to invalidate all keyreads until a keyhandling event is finished.

Thanks in advance.

Comments

[b][red]This message was edited by dj_sannie at 2004-3-30 15:59:15[/red][/b][hr]: Hello everyone. I have a simple question that's been keeping me stumped lately:: : How is it possible to invalidate a keyread while the previous keyevent is still in effect?: : Example of problem: Someone presses 'a' on the keyboard 7 times. In effect, this would mean that the key-handling event will be carried out 7 times in a row. If these key-handling events take a while, the program will be continuing these events for a long period of time. What I would like to do is to invalidate all keyreads until a keyhandling event is finished.: : Thanks in advance.: Hi,

U Could write a thread to handel the key actions. U can get something like this if u use a thread.[code]procedure TFormMain.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin if( MyThread == nil )then MyThread := MyThread.Create();end;[/code]Only one if statement left. that won't hang the program . It is not realy hard to make a thread, just look it up in the help files "TThread".

U Could also play with the time. But remember that this will only work if u have one single OnKeyPress event in you're application.[code]var LastKeyPressExit: Cardinal;

Try something like this. Create one thread object witch will perform than long time operations. Declare "flag" variable, some thing like IsThreadRunnig:Boolean. When you recive OnChar(or any other key event) you check the flag variable. If the thread is running you do nothing and if it doesn't set the flag variable and start the thread. If you use this method you can also cancel thread execution in response to some other event.

while PeekMessage(M, Handle, WM_KEYDOWN, WM_KEYDOWN, 0) <> false do begin If M.wParam=Ord('B') then {Check to see if we realy want to remove this message} PeekMessage(M, Handle, WM_KEYDOWN, WM_KEYDOWN, 1); end;end;[/code]