I am trying to capture when a user presses Ctrl+C in order to copy some text to the clipboard. If the user deliberately presses and holds Ctrl… then presses C it will register.
procedure <anObject>.KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (ssCtrl in Shift) and (upcase(Char(key)) = 'C')
then
begin
//Copy code
end;
end;
Is there a reason why this is happening?
Thanks!
Ctrl+C is translated to a character message. So you better use a
OnKeyPresshandler (which is fired in response to aWM_CHAR):update:
I believe what’s happening is this: when pressing quickly, the user is pressing ‘Ctrl’, then pressing ‘C’, then releasing ‘Ctrl’, lastly releasing ‘C’. As you can see when the OnKeyUp for ‘C’ is fired the ‘Ctrl’ key is already released. You won’t have this kind of problem with the translated message, if the OS registered the ‘copy’ key then OnKeyPress will be fired.