注:只考虑使用SendMessage方法实现,其它的办法请不用回复。
请在发出前测试您你的办法是否可行。感谢您的回复

解决方案 »

  1.   

    不对是这个:SendKeys "^{END}"
      

  2.   


    SendKeys 语句
          将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。语法SendKeys string[, wait]SendKeys 语句的语法具有以下几个命名参数:部分 描述 
    string 必需的。字符串表达式,指定要发送的按键消息。 
    Wait 可选的。指定等待方式的 [email protected] 值。如果为 False(缺省值),则控件在按键发送出去之后立刻返回到过程。如果为 True,则按键消息必须在控件返回到过程之前加以处理。 
    说明每个按键由一个或多个字符表示。为了指定单一键盘字符,必须按字符本身的键。例如,为了表示字母 A,可以用 "A" 作为 string。为了表示多个字符,就必须在字符后面直接加上另一个字符。例如,要表示 A、B 及 C,可用 "ABC" 作为 string。对 SendKeys 来说,加号 (+)、插入符 (^)、百分比符号 (%)、上划线 (~) 及圆括号 ( ) 都具有特殊意义。为了指定上述任何一个字符,要将它放在大括号 ({}) 当中。例如,要指定正号,可用 {+} 表示。方括号 ([ ]) 对 SendKeys 来说并不具有特殊意义,但必须将它们放在大括号中。在其它应用程序中,方括号有特殊意义,在出现动态数据交换 (DDE) 的时候,它可能具有重要意义。为了指定大括号字符,请使用 {{} 及 {}}。为了在按下按键时指定那些不显示的字符,例如 ENTER 或 TAB 以及那些表示动作而非字符的按键,请使用下列代码:按键 代码 
    BACKSPACE {BACKSPACE}, {BS}, 或 {BKSP} 
    BREAK {BREAK} 
    CAPS LOCK {CAPSLOCK} 
    DEL or DELETE {DELETE} 或 {DEL} 
    DOWN ARROW {DOWN} 
    END {END} 
    ENTER  {ENTER}或 ~ 
    ESC {ESC} 
    HELP {HELP} 
    HOME {HOME} 
    INS or INSERT {INSERT} 或 {INS} 
    LEFT ARROW {LEFT} 
    NUM LOCK {NUMLOCK} 
    PAGE DOWN {PGDN} 
    PAGE UP {PGUP} 
    PRINT SCREEN {PRTSC} 
    RIGHT ARROW {RIGHT} 
    SCROLL LOCK {SCROLLLOCK} 
    TAB {TAB} 
    UP ARROW {UP} 
    F1 {F1} 
    F2 {F2} 
    F3 {F3} 
    F4 {F4} 
    F5 {F5} 
    F6 {F6} 
    F7 {F7} 
    F8 {F8} 
    F9 {F9} 
    F10 {F10} 
    F11 {F11} 
    F12 {F12} 
    F13 {F13} 
    F14 {F14} 
    F15 {F15} 
    F16 {F16} 
    为了指定那些与 SHIFT、CTRL 及 ALT 等按键结合的组合键,可在这些按键码的前面放置一个或多个代码,这些代码列举如下:按键 代码 
    SHIFT + 
    CTRL  ^ 
    ALT % 
    为了说明在按下其它按键时应同时按下 SHIFT、CTRL、及 ALT 的任意组合键,请把那些按键的码放在括号当中。例如,为了说明按下 E 与 C 的时候同时按下 SHIFT 键,请使用 "+(EC)"。为了说明在按下 E 的时候同时按下 SHIFT 键,但接着按 C 而不按 SHIFT,则使用 "+EC"。为了指定重复键,使用 {key number} 的形式。必须在 key 与 number 之间放置一个空格。例如,{LEFT 42} 意指 42 次按下 LEFT ARROW 键;{h 10} 则是指 10 次按下 H 键。注意 不能用 SendKeys 将按键消息发送到这样一个应用程序,这个应用程序并没有被设计成在 Microsoft Windows 中运行。Sendkeys 也无法将 PRINT SCREEN 按键 {PRTSC} 发送到任何应用程序。
      

  3.   

    狂晕。
    我说过了,只考虑使用sendmessage的办法。晕晕的。不过,感谢你的回复
      

  4.   

    Option Explicit
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Const WM_KEYDOWN = &H100Private Sub Command1_Click()
        SendMessage Me.hwnd, WM_KEYDOWN, 35, 0
    End SubPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Debug.Print KeyCode
    End SubPrivate Sub Form_Load()
        Me.KeyPreview = True
    End Sub
      

  5.   

    上面只送了一个END键
    如果需要CTRL+END,
    则需要先送一个KEYDOWN CTRL(17),再送KEYDOWN END(35)\
    然后再送KEYUP END 、KEYUP CTRL
    代码我就不写了
      

  6.   

    用sendmessage发送消息的话,需要依次发送wm_keydown 和wm_keyup模拟一次按键,特别需要指出的是,此时sendmessage对应的lparam比较复杂,你需要参照msdn的说明逐一设置lparam的0-31位
      

  7.   

    WM_KEYUP Notification  
    --------------------------------------------------------------------------------The WM_KEYUP message is posted to the window with the keyboard focus when a nonsystem key is released. A nonsystem key is a key that is pressed when the ALT key is not pressed, or a keyboard key that is pressed when a window has the keyboard focus. SyntaxWM_KEYUP    WPARAM wParam
        LPARAM lParam;
        
    ParameterswParam
    Specifies the virtual-key code of the nonsystem key. 
    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. 
    0-15
    Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. The repeat count is always one for a WM_KEYUP message.
    16-23
    Specifies the scan code. The value depends on the 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_KEYUP message.
    30
    Specifies the previous key state. The value is always 1 for a WM_KEYUP message.
    31
    Specifies the transition state. The value is always 1 for a WM_KEYUP message.
    WM_KEYDOWN Notification  --------------------------------------------------------------------------------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. SyntaxWM_KEYDOWN    WPARAM wParam
        LPARAM lParam;
        
    ParameterswParam
    Specifies the virtual-key code of the nonsystem key. 
    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. 
    0-15
    Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated 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 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 zero if the key is up.
    31
    Specifies the transition state. The value is always zero for a WM_KEYDOWN message.