如何判断键盘按下的是 'enter','pageup','pagedown'键(100分)

  • 主题发起人 主题发起人 youli
  • 开始时间 开始时间
Y

youli

Unregistered / Unconfirmed
GUEST, unregistred user!
如何判断键盘按下的是 'enter','pageup','pagedown'键,即这几个键的表示方法。
(如:空格键可用Key=VK_Space 判断,但Key=Vk_Enter 为什么就出错?)
 
key=13 enter键
key=33 pageup键
key=34 pagedown键

你把key值showemassage出来就知道是什么了。
 
key值showemassage 如何实现?
 
onkeydown里加:
showmessage(key);
用以查看键值;
 
key=13 enter键
key=33 pageup键
key=34 pagedown键
 
去下载keyinfo,很简单实用的东西!
 
procedure TZydj_DjForm.FormKeyDown(Sender: TObject
var Key: Word;
Shift: TShiftState);
procedure Click(aDBNavButton: TwwNavButton);
begin
with aDBNavButton do if Enabled then Click;
Key:=0;
end;
begin
if Zy_DataModule.DataSource_Zydjb.DataSet.State in [dsInsert,dsEdit] then
case Key of
VK_ESCAPE (*#27*): Click(wwDBNavigator1Post);
$43 (*C*): if Shift = [ssCtrl] then Click(wwDBNavigator1Cancel);
end
else begin
case Key of
VK_PRIOR (*#33*): Click(wwDBNavigator1PriorPage);
VK_NEXT (*#34*): Click(wwDBNavigator1NextPage);
VK_INSERT(*#45*): Click(wwDBNavigator1Insert);
VK_DELETE(*#46*): Click(wwDBNavigator1Delete);
VK_HOME (*#36*): Click(wwDBNavigator1First);
VK_UP (*#38*): Click(wwDBNavigator1Prior);
VK_DOWN (*#40*): Click(wwDBNavigator1Next);
VK_LEFT (*#37*): Click(wwDBNavigator1Prior);
VK_RIGHT (*#39*): Click(wwDBNavigator1Next);
VK_END (*#35*): Click(wwDBNavigator1Last);
end;
if Shift = [ssCtrl] then
case Key of
$51 (*Q*): Click(wwDBNavigator1Button4)
//查询
$58 (*X*): Click(wwDBNavigator1Button1)
//退出
end;
end;
end;
 
Enter你可以用 "#13 "表示
pageup和pagedown也类似,在key值前加"#"号就可以了.
 
unit Unit1;
代码:
[:)][:)][:)]
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormShortCut(var Msg: TWMKey
var Handled: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShortCut(var Msg: TWMKey
var Handled: Boolean);
begin
case msg.CharCode of
13:label1.caption:='you pressed Enter';
33:label1.caption:='you pressed PageUp';
34:label1.caption:='you pressed PageDown';
end;
end;

end.
 
注意:回车键对应的值为VK_RETURN,而不是你说的VK_ENTER
 
数字键旁的回车和主键盘的回车代码是不一样的。
 
看看Windows SDK帮助吧,里面有所有按键VK值列表.
 
我的天,这个问题能回答的这么细致,youli还不散分??
我想答都无从下手了
 
后退
顶部