Attachment.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(KeyCodeShift)expression.KeyUp (KeyCode, Shift)

_運算式_代表**Attachment** 物件的變數。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,向上箭號,向下箭號,向右箭號、 向左箭號,並] 索引標籤。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 鍵,如果表單中包含命令按鈕的Default屬性設定為 [是]。The Enter key if the form has a command button for which the Default property is set to Yes.

  • 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 事件發生的第一個控制項、 KeyPressKeyUp 事件發生的第二個控制項時。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.