Solved

KeyPress event in a MDI-parent form

Posted on 2002-03-03
4
425 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
Comment Utility
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
Comment Utility
Forgot to say that the Sub Main can startup the MDI form.

0
 
LVL 2

Author Comment

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

Author Comment

by:dmarco
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now