Jump to content
Donald Shimoda

How to detect the active app

Recommended Posts

I want to detect the windows active app using a tray app. Is posible?

 

And how to detect if theres keyboard or mouse activity?

 

Best regards.

Share this post


Link to post
On 7/23/2020 at 3:47 AM, Donald Shimoda said:

I want to detect the windows active app using a tray app. Is posible?

GetTopWindow or GetActiveWindow, depending on your needs

 

On 7/23/2020 at 3:47 AM, Donald Shimoda said:

And how to detect if theres keyboard or mouse activity?

function SecondsIdle: DWord;
var
 liInfo: TLastInputInfo;
begin
 liInfo.cbSize := SizeOf(TLastInputInfo) ;
 GetLastInputInfo(liInfo) ;
 Result := (GetTickCount - liInfo.dwTime) DIV 1000;
end;

 

  • Like 1

Share this post


Link to post
13 hours ago, aehimself said:

GetTopWindow or GetActiveWindow, depending on your needs

GetTopWindow() returns the CHILD window that is at the top of the z-order of a specified PARENT window.

 

GetActiveWindow() returns the currently active window belonging to the CALLING THREAD (or another thread that is assigned to the message queue of the calling thread).

 

Neither of those are well-suited for finding the active window of ANOTHER app.  Have a look at GetForegroundWindow() instead.

Edited by Remy Lebeau
  • Like 3

Share this post


Link to post

I should pay more attention to the details; I thought I used one of these functions before. As I checked my sources - you are right. GetForegroundWindow it is.

Share this post


Link to post
2 hours ago, Remy Lebeau said:

Neither of those are well-suited for finding the active window of ANOTHER app.  Have a look at GetForegroundWindow() instead.

Thanks Remmy.

 

For check overall mouse and keyboard activity for windows which is the best option?

 

Best regards.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×