Solved

KeyPress event in a MDI-parent form

Posted on 2002-03-03
4
451 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

773 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