注:只考虑使用SendMessage方法实现,其它的办法请不用回复。
请在发出前测试您你的办法是否可行。感谢您的回复
请在发出前测试您你的办法是否可行。感谢您的回复
解决方案 »
- Winsock 的接收问题 高手指点 在线等
- VB+Access超级变态的问题:有谁遇到过?怎么解决?
- 给大家贡献一个教程网站.
- 大家給點意見: 在目前的中國,共享軟件能否做公司的主營業務? 要注意那些問題? 投資大小?
- textbox显示内容控制问题,急,顶着有分,不够可以另开帖子给分
- 文本框如何进行计算
- 求教一接收pop3邮件(可下载邮件到硬盘)的源代码,谢谢!!!
- 如何模仿这种情况
- 如何将ACCESS2003的表的结构和数据导入到SQL SERVER2008中
- 大家知道MVP是怎么评出来的吗?
- 用setup factory打包工具是如何调用他的Uninstall删除程序呢?
- VB6 ADO 连接 *.DB数据库 时出现的问题。
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} 发送到任何应用程序。
我说过了,只考虑使用sendmessage的办法。晕晕的。不过,感谢你的回复
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
如果需要CTRL+END,
则需要先送一个KEYDOWN CTRL(17),再送KEYDOWN END(35)\
然后再送KEYUP END 、KEYUP CTRL
代码我就不写了
--------------------------------------------------------------------------------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.