我窗口上有四个按钮,分别代替上、下、左、右,有如下代码: procedure Tform1.FormKeyPress(Sender: TObject; var Key: Char); var Temp:integer; begin if key=#38 then //up begin ...... end; 为什么我安下键,没有任务响应呢,而是 焦点 在控件上移来移去的,为何?
我发现用其它銉代替都可以,如i,j,k,l,就是不能用上、下,左、右、键来代替按纽
上、下,左、右、键都是采用了2个ASCII码,其中第一个代码为0,第二个是大写的P,H,M,K
if Key=37 then //写左移代码 else if Key=38 then //写上移代码 else if Key=39 then //写右移代码 else if Key=40 then ;//写下移代码
procedure Tform1.FormKeyPress(Sender: TObject; var Key: Char);
var
Temp:integer;
begin if key=#38 then //up
begin
......
end;
为什么我安下键,没有任务响应呢,而是 焦点 在控件上移来移去的,为何?
//写左移代码
else if Key=38 then
//写上移代码
else if Key=39 then
//写右移代码
else if Key=40 then
;//写下移代码
VK_LEFT
VK_RIGHT
VK_UP一般用WORD型,需要的话转换一下
建议使用KeyPress