procedure TForm1.RadioButton1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); 明白了不? Key:word
procedure TForm1.RadioButton1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin case key of 37:showmessage(''); 38:showmessage(''); 39:showmessage(''); 40:showmessage(''); end; end;
在 OnKeyDown事件中是可以的啊。 但是还是用WinAPI的函数更好。
组件: ----------------------------------------------- object RadioGroup1: TRadioGroup Left = 80 Top = 40 Width = 185 Height = 105 Caption = 'RadioGroup1' Columns = 2 Items.Strings = ( '1' '2' '3' '4') TabOrder = 0 end ----------------------------------------------- 代码: ----------------------------------------------- procedure TForm1.FormCreate(Sender: TObject); begin KeyPreview:= true; end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin with RadioGroup1 do if key=vk_up then ItemIndex:= 0 else if key=vk_down then ItemIndex:= 1 else if key=vk_left then ItemIndex:= 2 else ItemIndex:= 3; end; -----------------------------------------------
其中 Vk_Left=37 VK_Up=38 VK_RIGHT=39 Vk_DOWN=40
在OnKeyDown和OnKeyPress里面都可以查看key
注意一个为char,一个为word.
就象JYYF21所说的一样,我想你能把你的问题更详细点吗?
KEYPRESS事件不响应方向键
Shift: TShiftState);
明白了不?
Key:word
Shift: TShiftState);
begin
case key of
37:showmessage('');
38:showmessage('');
39:showmessage('');
40:showmessage('');
end;
end;
但是还是用WinAPI的函数更好。
-----------------------------------------------
object RadioGroup1: TRadioGroup
Left = 80
Top = 40
Width = 185
Height = 105
Caption = 'RadioGroup1'
Columns = 2
Items.Strings = (
'1'
'2'
'3'
'4')
TabOrder = 0
end
-----------------------------------------------
代码:
-----------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
KeyPreview:= true;
end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
with RadioGroup1 do
if key=vk_up then
ItemIndex:= 0
else if key=vk_down then
ItemIndex:= 1
else if key=vk_left then
ItemIndex:= 2
else
ItemIndex:= 3;
end;
-----------------------------------------------
程序员不会是以代码多为荣吧!职业杀手刺激为感觉。