|
-
Aug 21st, 2010, 05:32 PM
#1
Thread Starter
Fanatic Member
Check if app has focus? (External app)
So, I know from the user32 dll, and I set that as focused.
Is there a easy way of determining if the app has focus?
im using send keys, and i dont want it typing the keys and such, if the app doesnt have focus.
Also, if you click off of it, etc... It's more so a pause thing...
The only other way I can think of, is setting it so,
If myapp has focus, then pause the keysends.... then if it loses focus, assume the app i want has focus again.
-
Aug 21st, 2010, 06:55 PM
#2
Re: Check if app has focus? (External app)
you could use the GetActiveWindow API function to return the window handle of the active window, + then compare it to the window handle of the app you're looking for:
vb Code:
Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As integer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 22nd, 2010, 12:38 PM
#3
Re: Check if app has focus? (External app)
 Originally Posted by .paul.
you could use the GetActiveWindow API function to return the window handle of the active window, + then compare it to the window handle of the app you're looking for:
vb Code:
Public Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow"
() As integer
That should be an IntPtr not an Integer so that it works on 64 bit systems as well
-
Aug 22nd, 2010, 08:31 PM
#4
Thread Starter
Fanatic Member
Re: Check if app has focus? (External app)
i did the above, and it returns a number when MY app is selected, but as soon as my app is NOT selected... (on any other program, its 0)
-
Aug 22nd, 2010, 08:33 PM
#5
Thread Starter
Fanatic Member
Re: Check if app has focus? (External app)
not sure if you guys got what I meant,
but im trying to determine if say... Notepad had focus then sendkeys... if anything else has focus, dont.
-
Aug 22nd, 2010, 08:44 PM
#6
Thread Starter
Fanatic Member
Re: Check if app has focus? (External app)
Ok, I am using 'GetForegroundWindow' which is displaying a different # for each program.. So i'm going to assume thats what I want.
-
Aug 23rd, 2010, 03:15 AM
#7
Re: Check if app has focus? (External app)
Yeah that is the handle for each window, which will be what you want if you are then going to use that in another API call to do something to the window.
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
|