By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,143 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

OnKeyDown Event (When does it initially fire ?)

P: n/a
I'm using the OnKeyDown event in hopes of capturing a key being held
down during the initial startup of my application. Does anyone know,
at what point the OnKeyDown event fires?

I checked to see if the key would be captured in the OnOpen and OnLoad
or Initial OnCurrent event, but this does not seem to be the case.
Can I capture a key in these events?

Public CkOnOpenKey As Boolean
CkOnOpenKey = True 'Placed in the OnOpen event

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Key interpreter. Restricts keys.
If CkOnOpenKey Then
If KeyCode = 88 Then
MsgBox "The X key was pressed"
End If
End If
End Sub

Private Sub Form_Load()
'Check if he X key is pressed and held during the app startup
Call Pauser(2) 'Pause for 2 seconds
'The message "The X Key was pressed" should appear, but doesn't
CkOnOpenKey = False ' The app is running. Shut off the check
End Sub

Mar 9 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
It's not likely that a form can read an event that occurs before it's
life cycle starts. Kind of like asking a 4 year old what happened 5
years ago. However it may be possible to capture it with an API call.
This is tested only so far as it displays X as the last button pressed
(held down while opening form). May need to finagle it some to do what
you want, might be a starting point. Gleaned from API-Guide.

Insert into module..

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As
Long) As Integer

Function GetPressedKey() As String
Dim cnt As Long
For cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(cnt) <0 Then
GetPressedKey = Chr$(cnt)
Exit For
End If
Next cnt
End Function

Form event..

Private Sub Command0_Click()
MsgBox GetPressedKey
End Sub

Mar 9 '07 #2

P: n/a
The keyDown event happens when you put the key down, but when before
you open the application there is no event manager, so it won't fire.
It does not look at a key that is already down. Either open the
application from a different mdb, or have a form open on startup that
will then allow you to process keystrokes. What are you trying to
accomplish? tc
Ap******@gmail.com wrote:
I'm using the OnKeyDown event in hopes of capturing a key being held
down during the initial startup of my application. Does anyone know,
at what point the OnKeyDown event fires?

I checked to see if the key would be captured in the OnOpen and OnLoad
or Initial OnCurrent event, but this does not seem to be the case.
Can I capture a key in these events?

Public CkOnOpenKey As Boolean
CkOnOpenKey = True 'Placed in the OnOpen event

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'Key interpreter. Restricts keys.
If CkOnOpenKey Then
If KeyCode = 88 Then
MsgBox "The X key was pressed"
End If
End If
End Sub

Private Sub Form_Load()
'Check if he X key is pressed and held during the app startup
Call Pauser(2) 'Pause for 2 seconds
'The message "The X Key was pressed" should appear, but doesn't
CkOnOpenKey = False ' The app is running. Shut off the check
End Sub
Mar 9 '07 #3

P: n/a
>What are you trying to accomplish? tc
I have a Startup form that calls my MainMenu.
The Startup Form checks to make sure its environment is up to par (ie
Checks
the Version of Access, Checks if all the files that support the app
are available, etc...)

This form is never displayed, and simply does as I mentioned and then
calls the MainMenu.

I wanted to have a Keypressed (ie HeldDown) on startup, that would
allow me to launch a popup form before all these checks take place.
This popup form would allow me to change the FE Data, that I hope to
store info about the BE in.

I guess I'll have to put in a Pre-Startup form to do this ???

Thanks
Greg

Mar 9 '07 #4

P: n/a
Hello Mike

I tried the API call you supplied, and it worked. I'm not too
familiar with the API calls and am wondering if this is considered
unconventional, and if I will run into any issues with it depending
upon the environment (ie Version of Access or Windows) ???

I was hoping for a control sequence, like ctrl-alt-A Would I be able
to implement this using this function?

Where can I get more information on API calls (API Guide) ?

Thanks Again
Greg

Mar 9 '07 #5

P: n/a
On Mar 9, 6:02 pm, "ApexD...@gmail.com" <ApexD...@gmail.comwrote:
What are you trying to accomplish? tc

I have a Startup form that calls my MainMenu.
The Startup Form checks to make sure its environment is up to par (ie
Checks
the Version of Access, Checks if all the files that support the app
are available, etc...)

This form is never displayed, and simply does as I mentioned and then
calls the MainMenu.

I wanted to have a Keypressed (ie HeldDown) on startup, that would
allow me to launch a popup form before all these checks take place.
This popup form would allow me to change the FE Data, that I hope to
store info about the BE in.

I guess I'll have to put in a Pre-Startup form to do this ???

Thanks
Greg
Or just use the Shift-Click method, make your changes and re-start it.
Or display a splash screen for 5 seconds or show. Use the KeyDown or
KePress events of this form to interupt the process.

Mar 9 '07 #6

P: n/a
http://allapi.mentalis.org/agnet/apiguide.shtml

It's a great tool. There is another free one out there, but I can't
remember what it's called. It was really goo too.
I think it's no longer updated or maintained, but it has most of what
you'd need in it.

Since APIs can affect a great many things on a computer, most should
be employed with care. Take the time to understand them before you use
them. The MSDN web site details most if not all of them fairly well,
although some can be awkward to find.

They're not unconventional, but primarily used by more advanced users
and developers. There is nothing wrong with using and sometimes they
are better than the standard methods.

Most of the APIs are supported by any Windows version newer than 95,
but some do require the NT based versions (NT4, , 2000, XP).

Mar 10 '07 #7

P: n/a
Thanks again Mike for all the good info.

>Or just use the Shift-Click method, make your changes and re-start it.
This sounds interesting.

If you don't mind! What is the Shift-Click method and can I use it
without the API?

Greg

Mar 10 '07 #8

P: n/a

Hold down the Shift button while you double click the DB file icon or
a shortcut.
This prevents startup settings and the AutoExec macro (if there is
one) from running.
Make your changes or manually run other code to do so, then close and
restart normally.

(Reading my last few msgs - man I can't spell today)

Mar 10 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.