|
-
May 22nd, 2007, 09:44 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] GetAsyncKeyState
I've been playing with this, and have writting a nice program for my own use.
This program, however, is designed to stay open while I go do other stuff.
My problem: I can be in an entirely different window, yet if I hit one of the keys my program is reading, it tries to process it, causing great confusion to me.
So I am looking for
GetAsyncKeyStateButOnlyIfMyWindowIsActive
LOL
or, failing that, a test to see if my window is active. I could put that in the timer loop to ignore everything unless I am active.
Or maybe there is a better way? For example, a SUB to get control when my program becomes inactive (which could turn off the timer) and another one when it becomes active again (to turn timer on)
-
May 22nd, 2007, 11:17 AM
#2
Hyperactive Member
Re: GetAsyncKeyState
Any reason why KeyDown/KeyUp events aren't sufficient? Thats the path of least resistance.. Aside from that, just nest your GetAsyncKeystate inside a GetWindowPos type IF statement..
-
May 22nd, 2007, 02:57 PM
#3
Lively Member
Re: GetAsyncKeyState
You could try to use GetForegroundWindow
vb Code:
Public Declare Function GetForegroundWindow Lib "user32" () As Long
if GetForegroundWindow = me.hwnd then
'top window
else
'not top
end if
And throw it into a timer? Doesn't use up too much memory :-P I'm trying to think of somethin else but i would try keydown, keyup first...if i think of anything i'll throw it in here..
-
May 22nd, 2007, 02:59 PM
#4
Thread Starter
Hyperactive Member
Re: GetAsyncKeyState
 Originally Posted by triggernum5
Any reason why KeyDown/KeyUp events aren't sufficient
n00b = Mac
Actually, first I saw some stuff about GetAsyncKeyState and then I wrote a program around it just to see how it works and forgot that I didn't have to do that.
But after your suggestion, I ripped out all the TIMER/GetAsyncKeyState stuff and replaced it with KeyDown/KeyUp stuff. MUCH SIMPLER!!!
Thanks!!
Mac
-
May 22nd, 2007, 03:06 PM
#5
Lively Member
Re: GetAsyncKeyState
You learn somethin new everyday ;-)
-
May 22nd, 2007, 05:16 PM
#6
Thread Starter
Hyperactive Member
Re: GetAsyncKeyState
 Originally Posted by ixtrip
You learn somethin new everyday ;-)
LOL - Yep.
What didn't occur to me was that the GetAsyncKey stuff was really intended to get keypresses when you program was NOT in control. For example, a key logger. Or a program to wait for hot-keys and then initiate something.
It had no utility at all for a program that was in control. That program could simply read key events the normal way.
Oh, well. Live and learn. Actually, live and learn what you once knew already.
Mac
-
May 22nd, 2007, 05:36 PM
#7
Hyperactive Member
Re: GetAsyncKeyState
Actually, remember for the future that hotkeys have their own APIs.. RegisterHotkey and UnregisterHotkey IIRC.. Although you could build your own system with GetAsyncKeystate.. GetAsyncKeyState can go pretty hardcore if you dive into complex params..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|