Monday, 15 August 2011

Delphi - Detect pressing 3 keys at the same time -



Delphi - Detect pressing 3 keys at the same time -

i want observe pressing 3 keys in form illustration ctrl+c+n...the typed form need observe begin ctrl , next come 2 letters.

how ?

on arrival of 1 of keys, can if other key has been down. e.g.:

procedure tform1.formkeydown(sender: tobject; var key: word; shift: tshiftstate); begin if shift = [ssctrl] begin case key of ord('c'): if (getkeystate(ord('n')) , $80) = $80 showmessage('combo'); ord('n'): if (getkeystate(ord('c')) , $80) = $80 showmessage('combo'); end; end; end;

however observe instance n+ctrl+c, sequence not begin ctrl key. if doesn't qualify valid key combination, can maintain bit of key history help of flag. next should observe sequences begins ctrl:

type tform1 = class(tform) procedure formkeydown(sender: tobject; var key: word; shift: tshiftstate); procedure formkeyup(sender: tobject; var key: word; shift: tshiftstate); private fvalidkeycombo: boolean; end; ... procedure tform1.formkeydown(sender: tobject; var key: word; shift: tshiftstate); begin if fvalidkeycombo , (shift = [ssctrl]) case key of ord('c'): if (getkeystate(ord('n')) , $80) = $80 showmessage('combo'); ord('n'): if (getkeystate(ord('c')) , $80) = $80 showmessage('combo'); end; fvalidkeycombo := (shift = [ssctrl]) , (key in [ord('c'), ord('n')]); end; procedure tform1.formkeyup(sender: tobject; var key: word; shift: tshiftstate); begin fvalidkeycombo := false; end;

delphi

No comments:

Post a Comment