程序是这么写的!
procedure SendShift(H: HWnd; Down: Boolean);
var vKey, ScanCode, wParam: Word;
    lParam: longint;
begin
  vKey:= $10;
  ScanCode:= MapVirtualKey(vKey, 0);
  wParam:= vKey or ScanCode shl 8;
  lParam:= longint(ScanCode) shl 16 or 1;
  if not(Down) then lParam:= lParam or $C0000000;
  SendMessage(H, WM_KEYDOWN, vKey, lParam);
end;问题1 ScanCode:= MapVirtualKey(vKey, 0);为什么要这么写有什么含义吗?
      这么写有什么用意
问题2 lParam:= longint(ScanCode) shl 16 or 1;同上
问题3 if not(Down) then lParam:= lParam or $C0000000;
      这我就更加不明白了!
大家能不能详细一点的回答啊!我可是个菜鸟啊!说的不清楚我就看不明白!不好意思!有麻烦大家了!

解决方案 »

  1.   

    第一个问题不太清楚;
    第二,就是longint(ScanCode) 右移16位,再和1进行“或”运算;
    第三,如果“非”Down,那么lParam等于lParam 和 $C0000000 进行或运算。
    但愿能给你一点启示,OK?
      

  2.   

    看看帮助吧,你就会明白了
    MapVirtualKey的用法
    -----------------------------------------------------------
    The MapVirtualKey function translates (maps) a virtual-key code into a scan code or character value, or translates a scan code into a virtual-key code. UINT MapVirtualKey(
      UINT uCode,     // virtual-key code or scan code
      UINT uMapType   // translation to perform
    );
     
    Parameters
    uCode 
    Specifies the virtual-key code or scan code for a key. How this value is interpreted depends on the value of the uMapType parameter. 
    uMapType 
    Specifies the translation to perform. The value of this parameter depends on the value of the uCode parameter: Value Meaning 
    0 uCode is a virtual-key code and is translated into a scan code. If it is a virtual-key code that does not distinguish between left- and right-hand keys, the left-hand scan code is returned. If there is no translation, the function returns 0. 
    1 uCode is a scan code and is translated into a virtual-key code that does not distinguish between left- and right-hand keys. If there is no translation, the function returns 0. 
    2 uCode is a virtual-key code and is translated into an unshifted character value in the low-order word of the return value. Dead keys (diacritics) are indicated by setting the top bit of the return value. If there is no translation, the function returns 0. 
    3 uCode is a scan code and is translated into a virtual-key code that distinguishes between left- and right-hand keys. If there is no translation, the function returns 0. 
    Return Values
    The return value is either a scan code, a virtual-key code, or a character value, depending on the value of uCode and uMapType. If there is no translation, the return value is zero.Res
    An application can use MapVirtualKey to translate scan codes to the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU, and vice versa. These translations do not distinguish between the left and right instances of the shift, ctrl, or alt keys. An application can get the scan code corresponding to the left or right instance of one of these keys by calling MapVirtualKey with uCode set to one of the following virtual-key code constants. VK_LSHIFT VK_RSHIFT 
    VK_LCONTROL VK_RCONTROL 
    VK_LMENU VK_RMENU 
    These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.WM_KEYDOWN的用法
    ------------------------------------------------
    WM_KEYDOWN
    The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the alt key is not pressed. WM_KEYDOWN 
    nVirtKey = (int) wParam;    // virtual-key code 
    lKeyData = lParam;          // key data 
     
    Parameters
    nVirtKey 
    Value of wParam. Specifies the virtual-key code of the nonsystem key. 
    lKeyData 
    Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table. Value Description 
    0–15 Specifies the repeat count for the current message. The value is the number of times the keystroke is auto-repeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative. 
    16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM). 
    24 Specifies whether the key is an extended key, such as the right-hand alt and ctrl keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0. 
    25–28 Reserved; do not use. 
    29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message. 
    30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up. 
    31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message. 
    Return Values
    An application should return zero if it processes this message. Default Action
    If the f10 key is pressed, the DefWindowProc function sets an internal flag. When DefWindowProc receives the WM_KEYUP message, the function checks whether the internal flag is set and, if so, sends a WM_SYSCOMMAND message to the top-level window. The wParam parameter of the message is set to SC_KEYMENU. Res
    Because of the autorepeat feature, more than one WM_KEYDOWN message may be posted before a WM_KEYUP message is posted. The previous key state (bit 30) can be used to determine whether the WM_KEYDOWN message indicates the first down transition or a repeated down transition. For enhanced 101- and 102-key keyboards, extended keys are the right alt and ctrl keys on the main section of the keyboard; the ins, del, home, end, page up, page down and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and enter keys in the numeric keypad. Other keyboards may support the extended-key bit in the lKeyData parameter. 
     
      

  3.   

    to  see:  
    vk_LButton      =  $01;  
    vk_RButton      =  $02;  
    vk_Cancel        =  $03;  
    vk_MButton      =  $04;      {  NOT  contiguous  with  L  &  RBUTTON  }  
    vk_Back            =  $08;  
    vk_Tab              =  $09;  
    vk_Clear          =  $0C;  
    vk_Return        =  $0D;  
    vk_Shift          =  $10;  
    vk_Control      =  $11;  
    vk_Menu            =  $12;  
    vk_Pause          =  $13;  
    vk_Capital      =  $14;  
    vk_Escape        =  $1B;  
    vk_Space          =  $20;  
    vk_Prior          =  $21;  
    vk_Next            =  $22;  
    vk_End              =  $23;  
    vk_Home            =  $24;  
    vk_Left            =  $25;  
    vk_Up                =  $26;  
    vk_Right          =  $27;  
    vk_Down            =  $28;  
    vk_Select        =  $29;  
    vk_Print          =  $2A;  
    vk_Execute      =  $2B;  
    vk_SnapShot    =  $2C;  
    vk_Copy            =  $2C  not  used  by  keyboards  }  
    vk_Insert        =  $2D;  
    vk_Delete        =  $2E;  
    vk_Help            =  $2F;  
    vk_A  thru  vk_Z  are  the  same  as  their  ASCII  equivalents:  'A'  thru  'Z'  }  
    vk_0  thru  vk_9  are  the  same  as  their  ASCII  equivalents:  '0'  thru  '9'  }  
    vk_NumPad0      =  $60;  
    vk_NumPad1      =  $61;  
    vk_NumPad2      =  $62;  
    vk_NumPad3      =  $63;  
    vk_NumPad4      =  $64;  
    vk_NumPad5      =  $65;  
    vk_NumPad6      =  $66;  
    vk_NumPad7      =  $67;  
    vk_NumPad8      =  $68;  
    vk_NumPad9      =  $69;  
    vk_Multiply    =  $6A;  
    vk_Add              =  $6B;  
    vk_Separator  =  $6C;  
    vk_Subtract    =  $6D;  
    vk_Decimal      =  $6E;  
    vk_Divide        =  $6F;  
    vk_F1                =  $70;  
    vk_F2                =  $71;  
    vk_F3                =  $72;  
    vk_F4                =  $73;  
    vk_F5                =  $74;  
    vk_F6                =  $75;  
    vk_F7                =  $76;  
    vk_F8                =  $77;  
    vk_F9                =  $78;  
    vk_F10              =  $79;  
    vk_F11              =  $7A;  
    vk_F12              =  $7B;  
    vk_F13              =  $7C;  
    vk_F14              =  $7D;  
    vk_F15              =  $7E;  
    vk_F16              =  $7F;  
    vk_F17              =  $80;  
    vk_F18              =  $81;  
    vk_F19              =  $82;  
    vk_F20              =  $83;  
    vk_F21              =  $84;  
    vk_F22              =  $85;  
    vk_F23              =  $86;  
    vk_F24              =  $87;  
    vk_NumLock      =  $90;  
    vk_Scroll        =  $91;  Tab是#9  
    回车是#13,换行是#10等?  The  following  table  lists  the  virtual  key  codes  defined  in  the  Windows  unit:  
     
    Virtual  Key  Code            Corresponding  key  
     
    VK_LBUTTON            Left  mouse  button  
    VK_RBUTTON            Right  mouse  button  
    VK_CANCEL            Control+Break  
    VK_MBUTTON            Middle  mouse  button  
    VK_BACK            Backspace  key  
    VK_TAB            Tab  key  
    VK_CLEAR            Clear  key  
    VK_RETURN            Enter  key  
    VK_SHIFT            Shift  key  
    VK_CONTROL            Ctrl  key  
    VK_MENU            Alt  key  
    VK_PAUSE            Pause  key  
    VK_CAPITAL            Caps  Lock  key  
    VK_KANA            Used  with  IME  
    VK_HANGUL            Used  with  IME  
    VK_JUNJA            Used  with  IME  
    VK_FINAL            Used  with  IME  
    VK_HANJA            Used  with  IME  
    VK_KANJI            Used  with  IME  
    VK_CONVERT            Used  with  IME  
     
    VK_NONCONVERT            Used  with  IME  
    VK_ACCEPT            Used  with  IME  
    VK_MODECHANGE            Used  with  IME  
    VK_ESCAPE            Esc  key  
    VK_SPACE            Space  bar  
    VK_PRIOR            Page  Up  key  
    VK_NEXT            Page  Down  key  
    VK_END            End  key  
    VK_HOME            Home  key  
    VK_LEFT            Left  Arrow  key  
    VK_UP            Up  Arrow  key  
    VK_RIGHT            Right  Arrow  key  
    VK_DOWN            Down  Arrow  key  
    VK_SELECT            Select  key  
    VK_PRINT            Print  key  (keyboard-specific)  
    VK_EXECUTE            Execute  key  
    VK_SNAPSHOT            Print  Screen  key  
    VK_INSERT            Insert  key  
    VK_DELETE            Delete  key  
    VK_HELP            Help  key  
     
    VK_LWIN            Left  Windows  key  (Microsoft  keyboard)  
    VK_RWIN            Right  Windows  key  (Microsoft  keyboard)  
    VK_APPS            Applications  key  (Microsoft  keyboard)  
    VK_NUMPAD0            0  key  (numeric  keypad)  
    VK_NUMPAD1            1  key  (numeric  keypad)  
    VK_NUMPAD2            2  key  (numeric  keypad)  
    VK_NUMPAD3            3  key  (numeric  keypad)  
    VK_NUMPAD4            4  key  (numeric  keypad)  
    VK_NUMPAD5            5  key  (numeric  keypad)  
    VK_NUMPAD6            6  key  (numeric  keypad)  
    VK_NUMPAD7            7  key  (numeric  keypad)  
    VK_NUMPAD8            8  key  (numeric  keypad)  
    VK_NUMPAD9            9  key  (numeric  keypad)  
     
    VK_MULTIPLY            Multiply  key  (numeric  keypad)  
    VK_ADD            Add  key  (numeric  keypad)  
    VK_SEPARATOR            Separator  key  (numeric  keypad)  
    VK_SUBTRACT            Subtract  key  (numeric  keypad)  
    VK_DECIMAL            Decimal  key  (numeric  keypad)  
    VK_DIVIDE            Divide  key  (numeric  keypad)  
    VK_F1            F1  key  
    VK_F2            F2  key  
    VK_F3            F3  key  
    VK_F4            F4  key  
    VK_F5            F5  key  
    VK_F6            F6  key  
    VK_F7            F7  key  
    VK_F8            F8  key  
    VK_F9            F9  key  
    VK_F10            F10  key  
    VK_F11            F11  key  
    VK_F12            F12  key  
    VK_F13            F13  key  
    VK_F14            F14  key  
    VK_F15            F15  key  
     
    VK_F16            F16  key  
    VK_F17            F17  key  
    VK_F18            F18  key  
    VK_F19            F19  key  
    VK_F20            F20  key  
    VK_F21            F21  key  
    VK_F22            F22  key  
    VK_F23            F23  key  
    VK_F24            F24  key  
    VK_NUMLOCK            Num  Lock  key  
    VK_SCROLL            Scroll  Lock  key  
    VK_LSHIFT            Left  Shift  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
    VK_RSHIFT            Right  Shift  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
    VK_LCONTROL            Left  Ctrl  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
    VK_RCONTROL            Right  Ctrl  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
     
    VK_LMENU            Left  Alt  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
    VK_RMENU            Right  Alt  key  (only  used  with  GetAsyncKeyState  and  GetKeyState)  
    VK_PROCESSKEY            Process  key  
    VK_ATTN            Attn  key  
    VK_CRSEL            CrSel  key  
    VK_EXSEL            ExSel  key  
    VK_EREOF            Erase  EOF  key  
    VK_PLAY            Play  key  
    VK_ZOOM            Zoom  key  
    VK_NONAME            Reserved  for  future  use  
    VK_PA1            PA1  key  
    VK_OEM_CLEAR            Clear  key 
      

  4.   

    Delphi  键盘码表     
       
    VK_LBUTTON  =  1;  
    VK_RBUTTON  =  2;  
    VK_CANCEL  =  3;  
    VK_MBUTTON  =  4;  {  NOT  contiguous  with  L  &  RBUTTON  }  
    VK_BACK  =  8;  
    VK_TAB  =  9;  
    VK_CLEAR  =  12;  
    VK_RETURN  =  13;  
    VK_SHIFT  =  $10;  
    VK_CONTROL  =  17;  
    VK_MENU  =  18;  
    VK_PAUSE  =  19;  
    VK_CAPITAL  =  20;  
    VK_KANA  =  21;  
    VK_HANGUL  =  21;  
    VK_JUNJA  =  23;  
    VK_FINAL  =  24;  
    VK_HANJA  =  25;  
    VK_KANJI  =  25;  
    VK_CONVERT  =  28;  
    VK_NONCONVERT  =  29;  
    VK_ACCEPT  =  30;  
    VK_MODECHANGE  =  31;  
    VK_ESCAPE  =  27;  
    VK_SPACE  =  $20;  
    VK_PRIOR  =  33;  
    VK_NEXT  =  34;  
    VK_END  =  35;  
    VK_HOME  =  36;  
    VK_LEFT  =  37;  
    VK_UP  =  38;  
    VK_RIGHT  =  39;  
    VK_DOWN  =  40;  
    VK_SELECT  =  41;  
    VK_PRINT  =  42;  
    VK_EXECUTE  =  43;  
    VK_SNAPSHOT  =  44;  
    VK_INSERT  =  45;  
    VK_DELETE  =  46;  
    VK_HELP  =  47;  
    {  VK_0  thru  VK_9  are  the  same  as  ASCII  '0'  thru  '9'  ($30  -  $39)  }  
    {  VK_A  thru  VK_Z  are  the  same  as  ASCII  'A'  thru  'Z'  ($41  -  $5A)  }  
    VK_LWIN  =  91;  
    VK_RWIN  =  92;  
    VK_APPS  =  93;  
    VK_NUMPAD0  =  96;  
    VK_NUMPAD1  =  97;  
    VK_NUMPAD2  =  98;  
    VK_NUMPAD3  =  99;  
    VK_NUMPAD4  =  100;  
    VK_NUMPAD5  =  101;  
    VK_NUMPAD6  =  102;  
    VK_NUMPAD7  =  103;  
    VK_NUMPAD8  =  104;  VK_NUMPAD9  =  105;  
    VK_MULTIPLY  =  106;  
    VK_ADD  =  107;  
    VK_SEPARATOR  =  108;  
    VK_SUBTRACT  =  109;  
    VK_DECIMAL  =  110;  
    VK_DIVIDE  =  111;  
    VK_F1  =  112;  
    VK_F2  =  113;  
    VK_F3  =  114;  
    VK_F4  =  115;  
    VK_F5  =  116;  
    VK_F6  =  117;  
    VK_F7  =  118;  
    VK_F8  =  119;  
    VK_F9  =  120;  
    VK_F10  =  121;  
    VK_F11  =  122;  
    VK_F12  =  123;  
    VK_F13  =  124;  
    VK_F14  =  125;  
    VK_F15  =  126;  
    VK_F16  =  127;  
    VK_F17  =  128;  
    VK_F18  =  129;  
    VK_F19  =  130;  
    VK_F20  =  131;  
    VK_F21  =  132;  
    VK_F22  =  133;  
    VK_F23  =  134;  
    VK_F24  =  135;  
    VK_NUMLOCK  =  144;  
    VK_SCROLL  =  145;  
    {  VK_L  &  VK_R  -  left  and  right  Alt,  Ctrl  and  Shift  virtual  keys.  
    Used  only  as  parameters  to  GetAsyncKeyState()  and  GetKeyState().  
    No  other  API  or  message  will  distinguish  left  and  right  keys  in  this  way.  }  
    VK_LSHIFT  =  160;  
    VK_RSHIFT  =  161;  
    VK_LCONTROL  =  162;  
    VK_RCONTROL  =  163;  
    VK_LMENU  =  164;  
    VK_RMENU  =  165;  
    VK_PROCESSKEY  =  229;  
    VK_ATTN  =  246;  
    VK_CRSEL  =  247;  
    VK_EXSEL  =  248;  
    VK_EREOF  =  249;  
    VK_PLAY  =  250;  
    VK_ZOOM  =  251;  
    VK_NONAME  =  252;  
    VK_PA1  =  253;  
    VK_OEM_CLEAR  =  254    但愿有帮助。
      

  5.   

    wParam:= vKey or ScanCode shl 8;
    语法我都是明白的,但是就不知道有什么意图啊!为什么这么写!
      

  6.   

    使用 keybd_event API更为简便。