procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_RETURN then
    SendMessage(StringGrid1.Handle, WM_KeyDown, VK_Tab, 0);
end;

解决方案 »

  1.   

        
    CSDN首页 | 新闻聚焦 | 共享软件 | 俱乐部 | 开发文档 | 专家门诊 | 招聘求职 | Linux园地 | 程序员杂志 
    --------------------------------------------------------------------------------
     
    我要回复 | 我感兴趣 | 打印贴子 | 推荐给朋友 | 关闭窗口  
    主  题:!!!!如何将左方向键模仿成退格键!!!!//mysec
    作  者:mysec
    所属论坛:Delphi
    问题点数:50
    回复次数:14
    发表时间:2001-11-12 11:21:03
     
      
       
    回复贴子: 
    回复人: yopeng(鹏鹏) (2001-11-12 11:35:46)  得0分 
    试一下在keypress事件中把key的值该为#8  
    回复人: mysec(旺财) (2001-11-12 13:39:44)  得0分 
    不行的,用vk值和asc值都不行
      还有吗?  
    回复人: zswang(zs) (2001-11-12 13:50:23)  得0分 
    procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      case Key of
        VK_Left: begin
          Key := 0;
          SendKey(VK_BACK, []); //你给的分太少了我不答多的了,自己搜索一下"模仿按键"
        end;
      end;
    end;
     
    回复人: mysec(旺财) (2001-11-12 15:33:24)  得0分 
    不行,可以截获tab、backspace、return等键,但方向键不行
              高手现身  
    回复人: qiandeng(千灯) (2001-11-12 17:08:06)  得0分 
    要截获wm_keydown和wm_keyup两个事件
     
    回复人: liaokuo(辽阔) (2001-11-12 17:14:11)  得0分 
    form1有1个键盘属性,把所有键盘事件都在form继承  
    回复人: xueyin(雪莹) (2001-11-12 17:17:03)  得10分 
    我有一个控件, 告诉我你邮箱, 发给你, 可以截获键盘上的任何键. 还有一个演示程序.  
    回复人: xueyin(雪莹) (2001-11-12 17:17:39)  得0分 
    是我花了一张四人头的金子买来的  
    回复人: cszhz(丑小鸭) (2001-11-12 17:38:01)  得10分 
    VK_LEFT,可以注册一个键盘hook截获的。  
    回复人: mysec(旺财) (2001-11-13 9:05:09)  得0分 
    to 雪莹:
      贪财贪财,谢谢:  [email protected] 丑小鸭:
      可以么,麻烦你详细一些,加分不成问题谢谢各位兄弟姐妹了!  
    回复人: zswang(zs) (2001-11-13 9:54:23)  得30分 
    //我看不下去了
    procedure SendKey(const mKey: Word; mShiftState: TShiftState; mCount: Integer = 1); overload;
    const
      cExtended: set of Byte = [VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_HOME,
        VK_END, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE];  procedure pKeyboardEvent(mKey, mScanCode: Byte; mFlags: Longint);
      var
        vKeyboardMsg: TMsg;
      begin
        keybd_event(mKey, mScanCode, mFlags, 0);
        while PeekMessage(vKeyboardMsg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) do begin
          TranslateMessage(vKeyboardMsg);
          DispatchMessage(vKeyboardMsg);
        end;
      end; { pKeyboardEvent }  procedure pSendKeyDown(mKey: Word; mGenUpMsg: Boolean);
      var
        vScanCode: Byte;
        vNumState: Boolean;
        vKeyBoardState: TKeyboardState;
      begin
        if (mKey = VK_NUMLOCK) then begin
          vNumState := ByteBool(GetKeyState(VK_NUMLOCK) and 1);
          GetKeyBoardState(vKeyBoardState);
          if vNumState then
            vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] and not 1)
          else vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] or 1);
          SetKeyBoardState(vKeyBoardState);
          Exit;
        end;    vScanCode := Lo(MapVirtualKey(mKey, 0));
        if (mKey in cExtended) then begin
          pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY);
          if mGenUpMsg then
            pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
        end else begin
          pKeyboardEvent(mKey, vScanCode, 0);
          if mGenUpMsg then pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
        end;
      end; { pSendKeyDown }  procedure pSendKeyUp(mKey: Word);
      var
        vScanCode: Byte;
      begin
        vScanCode := Lo(MapVirtualKey(mKey, 0));
        if mKey in cExtended then
          pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
        else pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
      end; { pSendKeyUp }var
      I: Integer;
    begin
      for I := 1 to mCount do begin
        if ssShift in mShiftState then pSendKeyDown(VK_SHIFT, False);
        if ssCtrl in mShiftState then pSendKeyDown(VK_CONTROL, False);
        if ssAlt in mShiftState then pSendKeyDown(VK_MENU, False);
        pSendKeyDown(mKey, True);
        if ssShift in mShiftState then pSendKeyUp(VK_SHIFT);
        if ssCtrl in mShiftState then pSendKeyUp(VK_CONTROL);
        if ssAlt in mShiftState then pSendKeyUp(VK_MENU);
      end;
    end; { SendKey }procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      case Key of
        VK_Left: begin
          Key := 0;
          SendKey(VK_BACK, []); //便宜
        end;
      end;
    end; 
    回复人: mysec(旺财) (2001-11-13 10:47:02)  得0分 
      呵呵,不好意思,加分总可以了吧
              结帐  
    回复人: xueyin(雪莹) (2001-11-13 10:56:21)  得0分 
    我给你发过去, 得过会儿, 我另外一台电脑在重装系统, 你不用找, 我把控件发给你一定行,我化了两张四个人头的  
    回复人: zswang(zs) (2001-11-13 11:28:43)  得0分 
    SendKey(VK_F4, [ssAlt]); //关闭窗体
    自己发挥吧  
    --------------------------------------------------------------------------------
     
    我要回复:(请您对您的言行负责,遵守中华人民共和国有关法律、法规,尊重网上道德)  
    如果你只是觉得这个贴子好,而没想留言的话,请点击后面的贴子提前连接。   
    返回问题 | 关闭窗口   
       
     
               
    美达美简介 广告服务 英语步步高 程序员大本营 百联美达美科技有限公司  版权所有