I can't figure out how to capture the 'any key'(except for CTRL) + 'Deletekey' press. I found out how to validate if CTRL + 'Deletekey'.
The reason is because I need to make 2 actions:
- if 'CTRL' + 'Deletekey' is pressed. (Already achieved this one)
- ONLY if
'Deletekey'is pressed. (Got problems with it, because I can combine'any key'(except for CTRL) + Deletekeyand it keeps making action 2), but I need to make this action IF AND ONLY IF'Deletekey'is pressed.
Thanks
EDIT: Thank for your replies, I will show how I accomplished the point 1:
Context first: I have an event called DPaint1KeyUp, what it should do? remove graphically a painted element (if DELETE is pressed) or remove graphically and from the database if CTRL + DELETE pressed Simultaneously.
procedure TfMyClass.DPaint1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if (Shift = [ssctrl]) and (key = VK_DELETE) then
//Going to delete graphically and from database
if (Shift = []) and (key = VK_DELETE) then
//Going to delete just Graphically
end;
If I press simultaneosly CTRL + DELETE it works perfectly (Delete graphically and from Database.
BUT, if I press simultaneosly whichever combination with DELETE (except for CTRL), it deletes Graphically, WRONG, because if I only need to delete graphically I just need to press DELETE, not any other combination
For example:
@fpiette "A key and DeleteKey simultaneously pressed"
If you want to make sure that combination of pressed keys does not contain an undesired key you first need to get state of every key using GetKeyboardState function.
The above mentioned function returns an array with 256 items representing state of any possible key in Windows.
You can then iterate through the mentioned array checking if certain unwanted key is being pressed down using
Since each key state is stored at position in the above mentioned array that corresponds with Virtual Key value for that specific key you can use Virtual key designations to red the desired key from the above mentioned array.
And since key states are stored in high-order bit we use
andlogical operator with$80as its second parameter in order to read only the high-order bit value.If the key is being pressed down such value will be 1 otherwise it will be 0.
So your code would look something like this:
While this is probably not most efficient code it will get the job done. Just don't forget to add all desired keys that you do want to react to into
DesiredKeysset so them being pressed down wont exit theOnKeyUpprocedure.