如何同時偵測到多個按鍵在按著(任何按鍵不限 Shift State 的) |
|
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
其實只要建個 Set 在 KeyDown 時加入Set KeyUp 時從Set 移除便可以了。 附上的範例是按鍵移動一個 TEdit,可接受兩個方向同的按的複合鍵。 不想下載範例的看這裡的程式即可:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TKeys = Set of Char; TForm1 = class(TForm) Edit1: TEdit; procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); end; var Form1: TForm1; Keys : TKeys; implementation {$R *.dfm} procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Include(Keys,Char(Key)); if Char(VK_Up) in Keys then Edit1.Top := Edit1.Top - 1; if Char(VK_Down) in Keys then Edit1.Top := Edit1.Top 1; if Char(VK_Left) in Keys then Edit1.Left := Edit1.Left - 1; if Char(VK_Right) in Keys then Edit1.Left := Edit1.Left 1; end; procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin Exclude(Keys,Char(Key)); end; end.發表人 - Justmade 於 2003/07/02 09:14:44 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |