Solved

KeyPress event in a MDI-parent form

Posted on 2002-03-03
4
487 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

617 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