473,775 Members | 2,189 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Ke yCode 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 5131
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 GetAsyncKeyStat e 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 GetAsyncKeyStat e(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(Ke yCode 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
3912
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 different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and thus do not permit changing the assigned KeyCode. My question is this: How do I change the KeyCode...
3
7409
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
9174
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);}, false); }
3
8000
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 at startup and turning it off at the end of the OnLoad function but the SelectedIndexChange event gets called after OnLoad finishes, so my flag is off. How can I get around this? Is there another event that I can use to turn the flag off? Or...
0
2440
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 (http://support.microsoft.com/kb/810852), but then I realized that the hotfix mentioned was in .Net v1.1, which I am using. I took the sample from that article and recreated the situation I see in my application. (Code included below.) If you run the...
14
7449
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 DataSourceChanged has anything assigned. I can add it to the watch because it says it needs to be on the left side of a -= or +=. Thanks,
6
2366
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 side event not fire after the first click? Thanks, Brett
1
5759
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 // @namespace Devin Samarin // @description This automatcally selects the top result for your query. // @include *google.com/ig* // ==/UserScript== function makeRequest() {
12
4029
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, no items are selected. When the first item is selected by clicking either the left or right button, the SelectedIndexChanged event fires but not the MouseUp event. After the first item is selected and another item clicked on, both the...
0
9625
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10280
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8944
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7466
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5489
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4024
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2857
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.