procedure WMKEYDOWN(var Msg: TWMKEYDOWN); message WM_KEYDOWN;
begin
   if Msg.CharCode = VK_SHIFT then
   begin
     如何判断是按下了Shift和方向键 
   end
   else if Msg.CharCode = VK_Delete then
   begin
     
   end;
end;
我想实现像delphi设计时一样按下Shift和方向键就移动控件的坐标,就申明了上面的
消息处理过程,是判断 Msg结构中的什么成员才能知道是同时按下了Shift和方向键,
谢谢各位!!!!

解决方案 »

  1.   

    wm_keydown事件不能直接捕捉到 shift+key
    shift本身就会触发wm_keydown事件
      

  2.   

    在Delphi得OnKeyDown事件钟,可以写如下代码:
    if (Key = VK_UP) and (ssShift in Shift) then
      // do your things
      

  3.   

    GetAsyncKeyState(VK_SHIFT)<0   //按下了Shift键
    GetAsyncKeyState(VK_LEFT)<0    //按下了左键头键
    GetAsyncKeyState(VK_RIGHT)<0   //按下了右键头键
    GetAsyncKeyState(VK_UP)<0      //按下了上键头键
    GetAsyncKeyState(VK_DOWN)<0    //按下了下键头键GetKeyState 和 GetAsyncKeyState 的区别:
    GetKeyState:     从缓冲区取键的状态。比如按下Shift键之后,进入调试 状态,
                      松开了Shift键,此时得到的GetKeyState(VK_SHIFT)<0
    GetAsyncKeyState:判断当前的键的状态。比如按下Shift键之后,进入调试状态,
                      松开了Shift键,此时得到的GetKeyState(VK_SHIFT)>=0
      

  4.   

    一个显示所按的键的信息的程序,应该有帮助.const
      ctrl_A = 1;     { ASCII value for Ctrl+A }
      ctrl_Z = 26;    { ASCII value for Ctrl+Z }  FunctionKeys: array [vk_f1 .. vk_f12] of string[3] =
        ('F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8',
         'F9', 'F10', 'F11', 'F12');procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
      s: string;
    begin
      EditValue.Text:= IntToStr(Key);
      s := '';
      
      if ssShift  in Shift then 
        s := s + 'Shift+';
      if ssAlt    in Shift then 
        s := s + 'Alt+';
      if ssCtrl   in Shift then 
        s := s + 'Ctrl+';
        
      if Length(s) > 0 then
        Delete(s, Length(s), 1);
      EditShift.Text := s;
      if Key in [vk_f1 .. vk_f12] then
        EditChar.Text := FunctionKeys[Key]
      else
        EditChar.Text := '';
      if Key = vk_space then
        Key := 0;
    end;procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
    begin
      if Ord(Key) in [ctrl_A .. ctrl_Z] then
        EditChar.Text := '^' + Chr(Ord(Key) + Ord('A') - 1)
      else
        EditChar.Text := Key;
      EditValue.Text := IntToStr(Ord(Key));
    end;procedure TMainForm.FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      EditChar.Text := '';
      EditValue.Text := '';
      EditShift.Text := '';
    end;procedure TMainForm.ButtonExitClick(Sender: TObject);
    begin
      Application.Terminate;
    end;