|
 |
access thread: How to capture CTRL + any key
Message #1 by "Enzo" <enzaux@g...> on Sat, 18 May 2002 13:20:25 +0800
|
|
How would I capture the key entered for example CRTL + A or ALT + A etc.? I can capture keys entered like Enter or ESCape key,
what I don't know is how to get successive key entered or pressed on the keyboard.
Thanks,
Enzo
Message #2 by "Leo Scott" <leoscott@c...> on Sat, 18 May 2002 04:52:15 -0700
|
|
You have to use VBA and write code in the KeyPress event for the control or
the form. If you write it for the form you have to set the KeyPreview
property of the form or it won't see any keypresses while in the controls.
|-----Original Message-----
|From: Enzo [mailto:enzaux@g...]
|Sent: Friday, May 17, 2002 10:20 PM
|To: Access
|Subject: [access] How to capture CTRL + any key
|
|
|
| How would I capture the key entered for example CRTL + A or
|ALT + A etc.? I can capture keys entered like Enter or ESCape key,
|what I don't know is how to get successive key entered or pressed
|on the keyboard.
|
|Thanks,
|
|Enzo
|
|
|
|
Message #3 by "Enzo" <enzaux@g...> on Mon, 20 May 2002 10:06:00 +0800
|
|
I know it would in Keypress event, what I dont know is what would be my condition if ever I want to capture two successive key
pressed successively? Like for example, for capturing enter or esc key i use this code:
If keyascii = vbkeyreturn then 'or vbkeyesc
....my code goes here
end if
Thanks,
Enzo
-----Original Message-----
From: Leo Scott [mailto:leoscott@c...]
Sent: Saturday, May 18, 2002 7:52 PM
To: Access
Subject: [access] RE: How to capture CTRL + any key
You have to use VBA and write code in the KeyPress event for the control or
the form. If you write it for the form you have to set the KeyPreview
property of the form or it won't see any keypresses while in the controls.
|-----Original Message-----
|From: Enzo [mailto:enzaux@g...]
|Sent: Friday, May 17, 2002 10:20 PM
|To: Access
|Subject: [access] How to capture CTRL + any key
|
|
|
| How would I capture the key entered for example CRTL + A or
|ALT + A etc.? I can capture keys entered like Enter or ESCape key,
|what I don't know is how to get successive key entered or pressed
|on the keyboard.
|
|Thanks,
|
|Enzo
|
|
|
|
Message #4 by "Leo Scott" <leoscott@c...> on Sun, 19 May 2002 21:35:06 -0700
|
|
By the way you may need to use the keydown or keyup event because from the
help the keypress event:
A KeyPress event can involve any printable keyboard character, the CTRL key
combined with a character from the standard alphabet or a special character,
and the ENTER or BACKSPACE key.
If what you are looking for is a key combination outside these parameters
you have to use keydown or keyup.
|-----Original Message-----
|From: Enzo [mailto:enzaux@g...]
|Sent: Sunday, May 19, 2002 7:06 PM
|To: Access
|Subject: [access] RE: How to capture CTRL + any key
|
|
|
| I know it would in Keypress event, what I dont know is what
|would be my condition if ever I want to capture two successive key
|pressed successively? Like for example, for capturing enter or esc
|key i use this code:
|
| If keyascii = vbkeyreturn then 'or vbkeyesc
| ....my code goes here
| end if
|
|Thanks,
|
|Enzo
|
|-----Original Message-----
|From: Leo Scott [mailto:leoscott@c...]
|Sent: Saturday, May 18, 2002 7:52 PM
|To: Access
|Subject: [access] RE: How to capture CTRL + any key
|
|
|You have to use VBA and write code in the KeyPress event for the control or
|the form. If you write it for the form you have to set the KeyPreview
|property of the form or it won't see any keypresses while in the controls.
|
||-----Original Message-----
||From: Enzo [mailto:enzaux@g...]
||Sent: Friday, May 17, 2002 10:20 PM
||To: Access
||Subject: [access] How to capture CTRL + any key
||
||
||
|| How would I capture the key entered for example CRTL + A or
||ALT + A etc.? I can capture keys entered like Enter or ESCape key,
||what I don't know is how to get successive key entered or pressed
||on the keyboard.
||
||Thanks,
||
||Enzo
||
||
||
||
|
|
|
|
|
|
Message #5 by "Amy Wyatt" <amyw@c...> on Mon, 20 May 2002 13:23:15
|
|
This is how I did it for a memo box that I wanted to add a date to when
the user pressed Ctrl + D. Maybe this will help. This is in the Key_Down
event, in the KeyPress it is a little different because you need to use
the ASCII value rather than KeyCode which is then vbKeyCode values.
Private Sub txtActNotes_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strDateNote As String
If Me.txtActNotes.Locked = False And KeyCode = vbKeyD And (Shift _
And acCtrlMask) <> 0 Then
strDateNote = Me.txtActNotes & vbCrLf & vbCrLf _
& Format Date, "mm/dd/yyyy")
Me.txtActNotes = strDateNote
End If
End Sub
Hope this helps.
Amy
>
How would I capture the key entered for example CRTL + A or ALT +
A etc.? I can capture keys entered like Enter or ESCape key,
what I don't know is how to get successive key entered or pressed on the
keyboard.
Thanks,
Enzo
Message #6 by John Fejsa <John.Fejsa@h...> on Tue, 21 May 2002 08:38:20 +1000
|
|
1) Set Key Preview to Yes (either in Form Properties or in code as per
sample below)
Private Sub Form_Load()
On Error GoTo Err_Form_Load
Me.KeyPreview =3D True
Exit Sub
Err_Form_Load:
MsgBox Error, vbCritical, "Error on Form Load"
Exit Sub
End Sub
2) Evaluate key down and decide on the specific action, for example...
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
On Error GoTo Err_Form_Load
If Shift =3D 4 Then 'Alt key has been pressed
If KeyCode =3D vbKeyF4 Then (F4 has been pressed with Alt key --
Alt+F4
'Cancel Alt and F4 keys to stop the user from closing the
application by pressing Alt+F4 keys
Shift =3D 0
KeyCode =3D 0
End If
End If
Exit Sub
3) Check Access help for additional events and arguments. Here's a
sample:
The following example determines whether you have pressed the SHIFT, CTRL,
or ALT key.
To try the example, add the following event procedure to a form containing
a text box named KeyHandler.
Private Sub KeyHandler_KeyDown(KeyCode As Integer, Shift As Integer)
Dim intShiftDown As Integer, intAltDown As Integer
Dim intCtrlDown As Integer
' Use bit masks to determine which key was pressed.
intShiftDown =3D (Shift And acShiftMask) > 0
intAltDown =3D (Shift And acAltMask) > 0
intCtrlDown =3D (Shift And acCtrlMask) > 0
' Display message telling user which key was pressed.
If intShiftDown Then MsgBox "You pressed the SHIFT key."
If intAltDown Then MsgBox "You pressed the ALT key."
If intCtrlDown Then MsgBox "You pressed the CTRL key."
End Sub
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF2
' Process F2 key events.
Case vbKeyF3
' Process F3 key events.
Case vbKeyF4
' Process F4 key events.
Case Else
End Select
End Sub
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D
To create an event procedure that runs when the KeyDown or KeyUp event
occurs, set the OnKeyDown or OnKeyUp property to [Event Procedure], and
click the Build button .
Syntax
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Private Sub controlname_KeyDown(KeyCode As Integer, Shift As Integer)
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Private Sub controlname_KeyUp(KeyCode As Integer, Shift As Integer)
The KeyDown and KeyUp events have the following arguments.
Argument Description
controlname The name of the control whose KeyUp or KeyDown event
procedure you want to run.
KeyCode 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. You can prevent an object from receiving a keystroke by
setting KeyCode to 0.
Shift The state of the SHIFT, CTRL, and ALT keys at the time of the
event. If you need to test for the Shift argument, you can use one of the
following intrinsic constants as bit masks:
Constant Description
acShiftMask The bit mask for the SHIFT key.
acCtrlMask The bit mask for the CTRL key.
acAltMask The bit mask for the ALT key.
Remarks
You test for a condition by first assigning each result to a temporary
integer variable and then comparing the Shift argument to an intrinsic
constant. Use the And operator with the Shift argument to test whether the
condition is greater than 0, indicating that the SHIFT, CTRL, or ALT key
was pressed, as in the following example:
ShiftDown =3D (Shift And acShiftMask) > 0
In an event procedure, you can test for any combination of conditions, as
in the following example:
If ShiftDown And CtrlDown Then
. ' Do this if SHIFT and CTRL keys are pressed.
.
.
End If
You can use the KeyDown and KeyUp event procedures to interpret the
uppercase and lowercase version of each character by testing for both the
KeyCode argument and the Shift argument. The KeyCode argument indicates
the physical key pressed (thus, A and a are considered the same key), and
the Shift argument indicates the state of SHIFT+key and returns either A
or a.
Use the KeyDown and KeyUp event procedures for keyboard handlers if you
need to respond to both the pressing and releasing of a key.
You can respond to specific keys pressed in a form, regardless of which
control has the focus. For example, you may want the key combination
CTRL+X to always perform the same action on a form. To make sure a form
receives all keyboard events, even those that occur for controls, before
they occur for the controls, 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 keystrokes in the form's KeyDown, KeyPress and KeyUp events. You
can prevent a control from receiving keystrokes you've responded to, and
prevent the keyboard events from occurring for the control, by setting the
KeyCode argument to 0 for both the KeyDown and KeyUp events, and setting
the KeyAscii argument to 0 for the KeyPress event (if the key is an ANSI
key). You must set all three arguments to 0 if you don't want the control
to receive the keystrokes.
You can use the arguments for the KeyDown, KeyPress, and KeyUp events, in
conjunction with the arguments for the MouseDown, MouseUp, and MouseMove
events, to make your application work smoothly for both keyboard and mouse
users.
You can't cancel the KeyDown or KeyUp event.
The KeyDown and KeyUp events
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D
The KeyDown and KeyUp events occur when the user presses or releases a key
while the Calendar control has the focus. You can use these events to
determine when the user has either pressed a non-alphanumeric key or a
combination of keys, such as the SHIFT key with an alphanumeric key.
Syntax
Sub controlname_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
Sub controlname_KeyUp(KeyCode As Integer, ByVal Shift As Integer)
The KeyDown and KeyUp event procedures have the following arguments.
Argument Description
controlname The name of the Calendar control object.
KeyCode An integer that's a key code value. To see a list of possible
values, open the Object Browser, select VBA in the Project/Library box,
and select KeyCodeConstants in the Classes box.
Shift A value specifying the state of the SHIFT, CTRL, and ALT keys. The
following values are possible for the Shift argument.
Key pressed Value of the Shift argument
None 0
SHIFT 1
CTRL 2
ALT 4
SHIFT-CTRL 3
SHIFT-ALT 5
CTRL-ALT 6
SHIFT-CTRL-ALT 7
Remarks
You can use the KeyDown and KeyUp events to determine which key or
combination of keys has been pressed. Within the KeyDown or KeyUp event
procedure, check the value of the KeyCode argument to determine which key
was pressed. Check the value of the Shift argument to determine whether
the SHIFT, CTRL, or ALT key was pressed simultaneously.
I hope that will send you on the right track...
____________________________________________________
John Fejsa
Systems Analyst/Computer Programmer
Hunter Centre for Health Advancement
Locked Bag 10, WALLSEND NSW 2287
Phone: (02) 4924 6336 Fax: (02) 4924 6209
www.hcha.org.au
____________________________________________________
The doors we open and close each day decide the lives we live
____________________________________________________
CONFIDENTIALITY & PRIVILEGE NOTICE
The information contained in this email message is intended for the named
addressee only. If you are not the intended recipient you must not copy,
distribute, take any action reliant on, or disclose any details of the
information in this email to any other person or organisation. If you
have received this email in error please notify us immediately.
>>> enzaux@g... 18/05/2002 15:20:25 >>>
How would I capture the key entered for example CRTL + A or ALT +
A etc.? I can capture keys entered like Enter or ESCape key,
what I don't know is how to get successive key entered or pressed on the
keyboard.
Thanks,
Enzo
This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient,
please delete it and notify the sender. Views expressed in this message are those of the individual sender, and are not necessarily
the views of Hunter Health.
|
|
 |