Test for multiple key press combination within a form

P

Pete

Re Access 2003

I have created my own security and will subsequently disable the shift key
on startup.

In the startup form, I have set the keyPreview proprty to True.
My question is; how can I check for a (hopefully un-guessable) key
combination like:-
Shift + Ctrl + q + z (all pressed together)

This combination will then show the database window.

Many thanks.
 
J

Jeanette Cunningham

Hi Pete
from the help
Bit Masks

The Shift argument is a bit field, with the least significant bits
corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT
key (bit 2 ). These bits correspond to the values 1, 2, and 4, respectively.
The Shift argument indicates the state of these keys. Some, all, or none of
the bits can be set, indicating that some, all, or none of the keys is
pressed. For example, if both CTRL and ALT were pressed, the value of the
Shift argument would be 6.

The intrinsic constants that Microsoft Access provides for the Shift
argument have the following values.
Constant Value
acShiftMask 1
acCtrlMask 2
acAltMask 4

You can use the constants to test for any combination of buttons and keys
without having to figure out the unique bit field value for each
combination. A bit is set if the button or key is pressed.

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.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
P

Pete

Hi Jeanette.

Many thanks for your reply.

I can get the shift & Ctrl keys to work together in the way you have
highlighted below, but I cannot get it to work when I add any of the letter
keys to the combination.

Any pointers/examples would be greatly appreciated.

Many thanks.
 
S

sfisher973

I prefer a transparent button on the form somewhere, where the dbl-click
event opens a secondary/changeable "admin" password form.

1)Transparent buttons don't give any indication they are on the form, not
even the "mouse over" cursor change. You have to know where to find it. Like
sitting over the i in login. for example. (Format /Transparent Property )

2) dbl-clicking a button is something you don't normally do, so now you need
to know to dbl-click i in login.

3) and Then you need to know the "Admin" Password. (set the input mask to
PASSWORD for the textbox you use to collect it.)

There are other convolutions you could do as well like the transparent
button over the i in login is only enabled if you clicked a transparent
button somewhere else first... and so on...
 
P

Pete

Thanks Steve. That's certainly an option.

Is possible to (and how do you test for) 4 keys pressed simultaneously -
which include the Shift and Ctrl keys?

Many thanks.
 
P

Paul Shapiro

I don't think you can get q and z pressed simultaneously. The Ctrl, Alt and
Fn keys are made to work that way, but I'm pretty sure keyboards do not have
any code for simultaneous alphanumeric keypresses. Maybe you could start a
timer and see if the key sequence occurs within a fixed time limit.

I've used a <Ctrl><Shift> keypress while clicking a particular command
button as a hidden escape for the developer. The command button is just part
of the form interface, so there's nothing there to indicate to the users
that it has a special function. I like it because I can remember it.

However, if a user can read your code, they can find it easily. This would
only be reasonably secure if you are distributing an mde, where code is not
accessible.
 
S

-Steve

Paul is right BTW - press just about any key other than shift,ctrl and alt
simultaneously results in the first key pressed being sent with auto repeat
until you release it. Keyboards aren't meant to show multiple keys held
simultaneously by default. Can this characteristic be by passed by
accessing the keyboard driver directly? Maybe, but that’s pretty low level
stuff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top