Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

KeyPress event in a MDI-parent form

Posted on 2002-03-03
4
Medium Priority
?
498 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

705 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