Holding down a key to confirm an action

Rogerhar

Registered User.
Local time
Today, 10:57
Joined
Jul 11, 2005
Messages
16
I would like to prompt a user to hold down a key “D” while clicking ok on a msgbox "ok" for an action to run. I am not sure how you go about checking to make sure the D key is being pressed in code.


Any help would be greatly appreciated.

Thanks,
Roger
 
Generally checking for a key isn't tricky, but I'm not sure if you could check for it being held down while a message box is being clicked. What I do when having the user confirm something is use a Yes/No message box, and make No the default, so they can't just hit enter.
 
You need to look at events OnKeyUp, OnKeyDown, etc. Key Up and Key Down tell you when a key was pressed. If you look up keystrokes in the Help you will find that there is a way to capture the keystroke that led to the event being triggered. But beware that depending on auto-repeat keyboards and other vagaries of the multiplicity of keyboard types out there in the wide wonderful world, this approach is a bit more difficult than it might otherwise have been. I might take either PBaldy's approach or a tell-me-twice approach. "Delete file IO.SYS?" ... "REALLY delete file IOS.SYS?"
 
One other simple way to do this is to have a textbox in the form where they have to type in "confirm" or something. On the OK button's OnClick event, check that textbox. If it doesn't equal "confirm" or whatever you want it to be, then deny the OK click.
 

Users who are viewing this thread

Back
Top Bottom