Subject | Re: [IBO] Capturing keystrokes |
---|---|
Author | Geoff Worboys |
Post date | 2001-12-16T13:20:12Z |
> Any ideas how to flush the unnecessary keystrokes?There are ways of flushing the keyboard buffer (or there were under
DOS, I've never tried to access them within Windows). However I
suggest your best bet is to track whether a key that has been
processed has been released.
As Bill suggested, the simplest way is by using the OnKeyUp event.
However if you really want to event to occur while the key is down,
then you probably need something like like the following pseudo
code...
TForm1 = class( TForm )
...
private
FCurKey: ShortCut;
FFlag: integer;
...
FormKeyDown
if Key is one I want to track (alpha without ctrl or alt) then
begin
tmpShortCut := ShortCut(Key,Shift);
if FFlag = 0 then
FCurKey = tmpShortCut;
if FCurKey = tmpShortCut then
Inc(FFlag);
end;
FormKeyPress
if FFlag = 1 then // only process on first instance of keypress
accept the key
FormKeyUp
tmpShortCut = Shortcut(Key,Shift);
if tmpShortCut = FCurKey then
FFlag := 0;
I've done something similar to this in another application (somewhere
on my disk :-). I hope the above is enough to indicate what I mean.
--
Geoff Worboys
Telesis Computing