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.
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
Re: Check if app has focus? (External app)
Quote:
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 ;)
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)
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.
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.
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.