附件 KeyUp 事件 (Access)Attachment.KeyUp event (Access)

当用户释放某个键时窗体或控件具有焦点时,将发生 KeyUp 事件。The KeyUp event occurs when the user releases a key while a form or control has the focus. 如果您在窗体或控件使用 SendKeys 操作的宏或 Visual Basic 中的 SendKeys 语句发送击键,也会发生此事件。This event also occurs if you send a keystroke to a form or control by using the SendKeys action in a macro or the SendKeys statement in Visual Basic.

语法Syntax

表达式KeyUp(KeyCode, Shift)expression.KeyUp (KeyCode, Shift)

_表达式_一个代表**附件** 对象的变量。expression A variable that represents an Attachment object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
KeyCodeKeyCode 必需Required IntegerInteger 键代码, 如vbKeyF1 (F1 键) 或vbKeyHome (Home 键)。A key code, such as vbKeyF1 (the F1 key) or vbKeyHome (the Home key). 要指定键代码,请使用“对象浏览器”中显示的固有常量。To specify key codes, use the intrinsic constants shown in the Object Browser. 通过将_KeyCode_设置为 0, 可以阻止对象接收键击。You can prevent an object from receiving a keystroke by setting KeyCode to 0.
ShiftShift 必需Required IntegerInteger 在事件发生时的 Shift、Ctrl 和 Alt 键的状态。The state of the Shift, Ctrl, and Alt keys at the time of the event. 如果需要测试_Shift_参数, 可以使用下列固有常量之一作为位掩码:If you need to test for the Shift argument, you can use one of the following intrinsic constants as bit masks:
  • acShiftMask Shift 键的位掩码。acShiftMask The bit mask for the Shift key.

  • acCtrlMask Ctrl 键的位掩码。acCtrlMask The bit mask for the Ctrl key.

  • acAltMask Alt 键的位掩码。acAltMask The bit mask for the Alt key.

备注Remarks

KeyUp事件仅适用于窗体和窗体上的控件, 而不适用于报表上的控件。The KeyUp event applies only to forms and controls on a form, and not to controls on a report.

若要在这些事件发生时运行宏或事件过程,请将 OnKeyUp 属性设置为宏的名称或 [事件过程]。To run a macro or event procedure when these events occur, set the OnKeyUp property to the name of the macro or to [Event Procedure].

对于这两个事件,获得焦点的对象将接收到所有的键击事件。For both events, the object with the focus receives all keystrokes. 窗体只有在它没有控件或它所有可见的控件都失效时才能获得焦点。A form can have the focus only if it has no controls or all its visible controls are disabled.

窗体也能接收所有的键盘事件,甚至包括那些对控件发生,如果将窗体的 KeyPreview 属性设置为是。A form will also receive all keyboard events, even those that occur for controls, if you set the KeyPreview property of the form to Yes. 通过设置此属性值,所有键盘事件首先都发生该窗体,然后该控件具有焦点。With this property setting, all keyboard events occur first for the form, and then for the control that has the focus. 无论哪个控件获得焦点,都可以在窗体中对按下的特定键作出响应。You can respond to specific keys pressed in the form, regardless of which control has the focus. 例如, 您可能希望组合键 Ctrl + X 始终在窗体上执行相同的操作。For example, you may want the key combination Ctrl+X to always perform the same action on a form.

如果按下并按住某个键, 则KeyDownKeyPress事件将反复交替 (keydownKeyPressKeyDownKeyPress, 等等), 直到释放该键, 然后单击KeyUp事件发生.If you press and hold down a key, the KeyDown and KeyPress events alternate repeatedly (KeyDown, KeyPress, KeyDown, KeyPress, and so on) until you release the key, and then the KeyUp event occurs.

尽管在大部分键被按下时,将发生 KeyUp 事件,但它通常用于识别或区别:Although the KeyUp event occurs when most keys are pressed, it is typically used to recognize or distinguish between:

  • 扩展字符键,如功能键。Extended character keys, such as function keys.

  • 导航键, 如 Home、End、PgUp、PgDn、向上键、向下键、向右键、向左键和 Tab。Navigation keys, such as Home, End, PgUp, PgDn, Up arrow, Down arrow, Right arrow, Left arrow, and Tab.

  • 键和标准键盘修饰符 (Shift、Ctrl 或 Alt 键) 的组合。Combinations of keys and standard keyboard modifiers (Shift, Ctrl, or Alt keys).

  • 数字小键盘和键盘数字键。The numeric keypad and keyboard number keys.

当您按下时,就不会发生 KeyUp 事件:The KeyUp event does not occur when you press:

  • 如果窗体的某个命令按钮的默认属性设置为 "是", 则 Enter 键。The Enter key if the form has a command button for which the Default property is set to Yes.

  • 如果窗体的某个命令按钮的Cancel属性设置为 "是", 则该参数为 Esc。The Esc key if the form has a command button for which the Cancel property is set to Yes.

任何事件之后, KeyUp 事件发生按下或发送键引起控件。The KeyUp event occurs after any event for a control caused by pressing or sending the key. 如果键击导致焦点从一个控件移动到另一个控件,将发生 KeyDown 事件有关的第一个控件的 按键KeyUp 事件发生的第二个控件。If a keystroke causes the focus to move from one control to another control, the KeyDown event occurs for the first control, while the KeyPress and KeyUp events occur for the second control.

若要找出对应于按下的键的 ANSI 字符,使用 KeyPress 事件。To find out the ANSI character corresponding to the key pressed, use the KeyPress event.

如果模式对话框显示由于按下或发送键,则 KeyDownKeyPress 事件发生,但不会发生 KeyUp 事件。If a modal dialog box is displayed as a result of pressing or sending a key, the KeyDown and KeyPress events occur, but the KeyUp event doesn't occur.

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.