473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OnKeyDown Event (When does it initially fire ?)

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
8 5108
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
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
>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
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
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a...
3
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
10
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
3
by: sandman | last post by:
I've got a combo box that has an event handler set for SelectedIndexChanged event. The problem is that it's firing at startup when I load data from the Form_OnLoad event. I tried setting a flag...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
14
by: Brett Romero | last post by:
I'm using a DataGrid and have assigned this.DataSourceChanged += new EventHandler( DataGrid_DataSourceChanged ); This works fine but there is one case where it doesn't. How can I check if...
6
by: erdos | last post by:
I have an asp.net 2.0 button with server and client side click events. On the first click, both events will fire. On the next click, only the client side event fires. How do I make the server...
1
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest //...
12
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.