Solved

KeyPress event in a MDI-parent form

Posted on 2002-03-03
4
460 Views
Last Modified: 2012-06-21
Hi friends,

I'm working at a MDI project, where the starting object is the MDI-parent form. Sometimes I need to stop the program AFTER loading the MDI-parent form and BEFORE loading the MDI-child form(s). This could be done simply using a MsgBox that prompts the user:  "Do you want to stop the program? y/n". However, this doesn't seem me the best solution. It would be better to stop the program execution pressing a key, but unfortunately the MDI-parent form hasn't a keyPress event ... How can I do?
It must be said that in my code the formLoad event of the MDI-parent form loads the MDI-child form.
0
Comment
Question by:dmarco
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 200 total points
ID: 6838158
There are windows API calls which can reveal which kets are down.  The in an example to detect if the control key is down.

Create a module:

Create a Sub Main()

And set the "project properties" - "startup object" for the project as Sub Main()

In you sub main you can test any keystate required.

Here is an example which tests for Ctrl.

Public Const VK_LSHIFT = &HA0
Public Const VK_RSHIFT = &HA1
Public Const VK_LCONTROL = &HA2
Public Const VK_RCONTROL = &HA3


Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer

Function IsControlDown() As Boolean
' Is the Left or right control key down
Dim resLeft As Long
Dim resRight As Long
resLeft = GetKeyState(VK_LCONTROL)
resRight = GetKeyState(VK_RCONTROL)
If (resLeft And 1) Or (resRight And 1) Then
    IsControlDown = True
Else
    IsControlDown = False
End If
End Function
0
 
LVL 17

Expert Comment

by:inthedark
ID: 6838172
Forgot to say that the Sub Main can startup the MDI form.

0
 
LVL 2

Author Comment

by:dmarco
ID: 6840035
thanks, I need some time to check your suggestion...
0
 
LVL 2

Author Comment

by:dmarco
ID: 6842674
OK, GetKeyState function works.
 
I declared it in the module of my project and I called it directly in the form_Load event of the MDI form. Therefore there is no need to change the "startup object".

Thanks for help.
Marco.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question