vb里程序怎么调用alt+f4这样的键盘按钮

fengstudios 2003-08-20 10:56:36
谢谢
...全文
403 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
captainivy 2003-11-06
  • 打赏
  • 举报
回复
up
flc 2003-08-21
  • 打赏
  • 举报
回复
up
yunok 2003-08-20
  • 打赏
  • 举报
回复
也可以用模拟键盘的函数keybd_event
lihonggen0 2003-08-20
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
SendKeys "%{F4}"
End Sub
wumy_ld 2003-08-20
  • 打赏
  • 举报
回复
Overview | Methods | This Package | All Packages

SendKeys.sendKeys

Sends keystrokes to the active application.

Syntax


public static void sendKeys( String keys )
Parameters

key

The string of keystrokes to send.

Remarks

Use the sendKeys method to send keystrokes or combinations of keystrokes to the currently active application or to control another application that your application has started or is using. The sendKeys method does not wait for any processes started by the keystroke to return before continuing with code execution.

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, assign "A" to the method. To represent more than one character, append each additional character to the one preceding it. To represent the letters A, B, and C, assign "ABC" to the method.

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses (( )) have special meanings to sendKeys. To specify one of these characters, enclose it in braces ({}). For example, to specify the plus sign, use {+}. Brackets ([ ]) have no special meaning to sendKeys, but you must enclose them in braces. To specify brace characters, use {{} and {}}.

To specify characters, such as ENTER or TAB, that aren't displayed when you press a key and keys that represent actions rather than characters, use the codes shown in the following table.

Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {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}

To specify keys combined with any combination of the SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following codes.

Key Code
SHIFT +
CTRL ^
ALT %

To specify that any combination of SHIFT, CTRL, and ALT should be held down while several other keys are pressed, enclose the code for those keys in parentheses. For example, to specify to hold down SHIFT while E and C are pressed, use +(EC). To specify to hold down SHIFT while E is pressed, followed by C without SHIFT, use +EC.

lihonggen0 2003-08-20
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
SendKeys "%{F4}"
End Sub
wumy_ld 2003-08-20
  • 打赏
  • 举报
回复
呵呵,用SendKeys了。
看看msdn
victorycyz 2003-08-20
  • 打赏
  • 举报
回复
SendKeys "%({f4})"
victorycyz 2003-08-20
  • 打赏
  • 举报
回复
SendKeys "%({f4})"
xsp 2003-08-20
  • 打赏
  • 举报
回复
SendKeys "%{F4}"
sunrise10 2003-08-20
  • 打赏
  • 举报
回复
KeyDown、KeyUp 事件


这些事件是当一个对象具有焦点时按下 ( KeyDown ) 或松开 ( KeyUp ) 一个键时发生的。(要解释 ANSI 字符,应使用 KeyPress 事件。)

语法

Private Sub Form_KeyDown(keycode As Integer, shift As Integer)

Private Sub object_KeyDown([index As Integer,]keycode As Integer, shift As Integer)

Private Sub Form_KeyUp(keycode As Integer, shift As Integer)

Private Sub object_KeyUp([index As Integer,]keycode As Integer, shift As Integer)

KeyDown 和 KeyUp 事件包括下列部分:

部分 描述
object 一个对象表达式,其值是“应用于”列表中的一个对象。
index 是一个整数,它用来唯一标识一个在控件数组中的控件。
keycode 是一个键代码,诸如 vbKeyF1 ( F1 键)或 vbKeyHome ( HOME 键)。要指定键代码,可使用对象浏览器中的 Visual Basic ( VB ) 对象库中的常数。
shift 是在该事件发生时响应 SHIFT ,CTRL 和 ALT 键的状态的一个整数。shift 参数是一个位域,它用最少的位响应 SHIFT 键(位 0 )、CTRL 键(位 1 )和 ALT 键(位 2 )。这些位分别对应于值 1、2 和 4。可通过对一些、所有或无位的设置来指明有一些、所有或零个键被按下。例如,如果 CTRL 和 ALT 这两个键都被按下,则 shift 的值为 6。


说明

对于这两个事件来说,带焦点的对象都接收所有击键。一个窗体只有在不具有可视的和有效的控件时才可以获得焦点。虽然 KeyDown 和 KeyUp 事件可应用于大多数键,它们最经常地还是应用于:

扩展的字符键如功能键等。


定位键。


键盘修饰键和按键的组合。


区别数字小键盘和常规数字键。
在需要对按下和松开一个键都响应时,可使用 KeyDown 和 KeyUp 事件过程。

下列情况不能引用 KeyDown 和 KeyUp 事件:

窗体有一个 CommandButton 控件,并且 Default 属性设置为 True 时的 ENTER 键。


窗体有一个 CommandButton 控件,并且 Cancel 属性设置为 True 时的 ESC 键。


TAB 键。
KeyDown 和 KeyUp 用两种参数解释每个字符的大写形式和小写形式:keycode —显示物理的键(将 A 和 a 作为同一个键返回)和 shift —显示 shift + key 键的状态而且返回 A 或 a 其中之一。

如果需要测试 shift 参数,可使用该参数中定义各位的 shift 常数。该常数有下列值:

常数 值 描述
vbShiftMask 1 SHIFT 键的位屏蔽。
VbCtrlMask 2 CTRL 键的位屏蔽。
VbAltMask 4 ALT 键的位屏蔽。


该常数用作位屏蔽。它可被用来测试任何键组合。

测试一个条件时,首先将每个结果分配给一个临时整数变量,然后将 shift 与一个位屏蔽进行对比。如下例,可用 And 运算符和 shift 参数一起来测试条件是否大于 0。该条件说明该修正键被按下:

ShiftDown = (Shift And vbShiftMask) > 0

可按此例在一个过程中测试任何条件的组合:

If ShiftDown And CtrlDown Then

注意 如果 KeyPreview 属性被设置为 True,则一个窗体先于该窗体上的控件接收到此事件。可用 KeyPreview 属性来创建全局键盘处理例程。
sunrise10 2003-08-20
  • 打赏
  • 举报
回复
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 115 And Shift = 4 Then
………………
End If
End Sub
didishu0807 2003-08-20
  • 打赏
  • 举报
回复
代码调用F4 :SendKeys "%({f4})"
junhrb 2003-08-20
  • 打赏
  • 举报
回复
SendKeys "%{F4}"
doudou8090 2003-08-20
  • 打赏
  • 举报
回复
UP

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧