A1VBCode Forums

Ripping Hair out: Get(Async)KeyState API Help PLEASE!


http://www.a1vbcode.com/vbforums/Topic12578.aspx

By rj_budz - 7/7/2005

I've adopted legacy code (yech!) that requires a lot of debugging & enhancement. 

This is an MS Access "application" so I'm using VBA to do all this.

I thought it'd be great if I could have users click a control, form, whatever, with the right mouse button and have a bug-report form pop up allowing him/her to enter data about the item in question.

I accomplished this by using GetAsyncKeyState(VB_RBUTTON) in a timer sub.  Works great.  EXCEPT for one thing, and you probably already know what that is.

Because GetAsyncKeyState is an API, my pop-up dialog will show itself when the right button is clicked NO MATTER WHAT APPLICATION the user has active.  So if he/she has my app running, then goes to Internet Explorer and right clicks, well, you know.

Obviously this is NOT what I want to happen. I do not want bug reports for Internet Explorer. I only want my bug form to show up if my app has focus.

I tried the Screen object to determine what has focus, but this doesn't work because at the time I query this object, Access will always be the active app, since this is when the code is executing from.

Variations on GetKeyState don't help either.

Suggestions, please?  At least a point in the right direction?

Thanks.  I'm gonna go call Hair Club now....

By kwandobe - 8/31/2005

In your code before where it loops looking for the key to be pushed you need to add something like:

Public NoFocus as Boolean

If NoFocus Then Exit Sub

and in the forms GotFocus you need to put

NoFocus = False

in the forms LostFocus you need to put

NoFocus = True