[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Keydown or KeyPress within module

Posted on 2004-03-30
2
Medium Priority
?
1,003 Views
Last Modified: 2010-07-27
Hello,

I have a form that calls a function contained within a module when a button is pressed.  Is there anyway from within the module to capture and handle the Keydown or KeyPress events?  Thanks.

Mike
0
Comment
Question by:ingenito
[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 Comments
 
LVL 11

Accepted Solution

by:
YohanShminge earned 200 total points
ID: 10719364
You can use the GetAsyncKeyState API to get the state of a single key:

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

If GetAsyncKeyState(vbKeyEscape) Then
   'Do some stuff
End If
0
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 10720168
GetAsyncKeyState is good if you need to check the state at the time the procedure is called.

If you want to know about future changes...well, you can't use a standard module.  The best you could do would be to put the relevant code in a class module, and create an instance of the class from the standard module.

'Class code for capturing events - MyEventCapture:

Public WithEvents MyForm as Form

Private Sub MyForm_KeyPress(KeyAscii as Integer)
   'Do something
End Sub

'Standard module code

Private Capture as New MyEventCapture

Sub DoSomething(WithForm as Form)
   Set Capture.MyForm = WithForm
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
Suggested Courses

649 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