怎么判断键盘按下的是回车键呢

解决方案 »

  1.   

    procedure TForm1.WMKEYdownClick(var Msg: TWMKEYDOWN);
    begin
        if Msg.Msg = vk_Return then
        begin
           showmessage('ok');
        end;
    end;这样写为什么不起作用啊
      

  2.   

    在keypress中写if key=#13 then
    begin
       showmessage('ok'); 
    end;
      

  3.   

    知道了; 应该是if Msg.CharCode = VK_RETURN then
      

  4.   

    在keypress事件中写
    if key=#13 then
    begin
       showmessage('按下的是回车键'); 
    end;
      

  5.   

    在keypress事件中写
    if key=#13 then
    begin
       showmessage('按下的是回车键'); 
    end;楼上说得没有错误
      

  6.   

    keypress中写
    if key=#13 then
    begin
       showmessage('按写了回车'); 
    end;
    或在mainmenu里创建一个 不可见项(如‘enter’) shortcut里 输入enter
    在‘enter’的onclick里写 你想执行的事件
      

  7.   

    最好使用keydown事件,keypress事件是对可见的按键的事件.
    keydown:if key=vk_return then
    begin
    .....
    end ;
      

  8.   

    确实是在keypress中操作,通过key的值判断
      

  9.   

    不起作用可能是因为控件的焦点不在Form 上,被其他控件接走了。你可以跟踪一下看看有没有收到消息,我估计你在窗体里面响应这个消息是收不到的。
      

  10.   

    if key=#13 thenif int(key)=13 thenif ord(key)=13 then