Donald Shimoda 0 Posted July 23, 2020 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
aehimself 396 Posted July 24, 2020 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; 1 Share this post Link to post
Remy Lebeau 1393 Posted July 24, 2020 (edited) 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 July 24, 2020 by Remy Lebeau 3 Share this post Link to post
aehimself 396 Posted July 24, 2020 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
Donald Shimoda 0 Posted July 24, 2020 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
Remy Lebeau 1393 Posted July 24, 2020 1 hour ago, Donald Shimoda said: For check overall mouse and keyboard activity for windows which is the best option? Depends on your needs. You could use GetLastInputInfo() in a loop/timer. Or you could use SetWindowsHookEx() or RegisterRawInputDevices() to receive real-time events from the mouse/keyboard directly. Share this post Link to post