全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2423
推到 Plurk!
推到 Facebook!

請問按鍵精靈的鍵盤部分是怎樣做的?

答題得分者是:Vicen
Tak
一般會員


發表:17
回覆:18
積分:7
註冊:2003-01-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-10-13 14:56:44 IP:202.125.xxx.xxx 未訂閱
按下Form中一個Button, 等於按下'A'鍵的效果, 是怎樣做的呢?
Vicen
高階會員


發表:13
回覆:145
積分:151
註冊:2005-03-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-10-13 15:09:11 IP:221.226.xxx.xxx 未訂閱
发送键盘使用 keybd_event;    下面是一个模拟键盘输入的函数,下面还有使用例程,可以参考一下:    
    Procedure PostKeyEx32( key: Word; Const shift: TShiftState; specialkey: Boolean ); 
      {************************************************************ 
      * Procedure PostKeyEx32 
      * 
      * Parameters: 
      * key : virtual keycode of the key to send. For printable 
      * keys this is simply the ANSI code (Ord(character)). 
      * shift : state of the modifier keys. This is a set, so you 
      * can set several of these keys (shift, control, alt, 
      * mouse buttons) in tandem. The TShiftState type is 
      * declared in the Classes Unit. 
      * specialkey: normally this should be False. Set it to True to 
      * specify a key on the numeric keypad, for example. 
      * Description: 
      * Uses keybd_event to manufacture a series of key events matching 
      * the passed parameters. The events go to the control with focus. 
      * Note that for characters key is always the upper-case version of 
      * the character. Sending without any modifier keys will result in 
      * a lower-case character, sending it with [ssShift] will result 
      * in an upper-case character! 
      *Created: 17.7.98 by P. Below 
      ************************************************************} 
     
    Type 
      TShiftKeyInfo = Record 
        shift: Byte; 
        vkey : Byte; 
      End; 
      byteset = Set of 0..7; 
    Const 
      shiftkeys: Array [1..3] of TShiftKeyInfo = 
        ((shift: Ord(ssCtrl); vkey: VK_CONTROL ), 
        (shift: Ord(ssShift); vkey: VK_SHIFT ), 
        (shift: Ord(ssAlt); vkey: VK_MENU )); 
    Var 
      flag: DWORD; 
      bShift: ByteSet absolute shift; 
      i: Integer; 
    Begin 
      For i := 1 To 3 Do 
      Begin 
        If shiftkeys[i].shift In bShift Then 
          keybd_event( shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), 0, 0); 
      End; { For }           If specialkey Then 
        flag := KEYEVENTF_EXTENDEDKEY 
      Else 
        flag := 0; 
      
      keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 ); 
      flag := flag or KEYEVENTF_KEYUP; 
      keybd_event( key, MapvirtualKey( key, 0 ), flag, 0 ); 
     
      For i := 3 DownTo 1 Do Begin 
        If shiftkeys[i].shift In bShift Then 
          keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), KEYEVENTF_KEYUP, 0); 
      End; { For } 
    End; { PostKeyEx32 } 
使用方法 按下 A 键: PostKeyEx32(ORD('A'), [], FALSE); 还可以发组合键,如 Ctrl Alt C: PostKeyEx32(ORD('C'), [ssctrl, ssAlt], FALSE); 發表人 - vicen 於 2005/10/13 15:13:14
系統時間:2024-04-26 9:14:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!