I'm trying to create a RoboTask to create a log of each application used and for how long. It is enough to create a file with Date, Time and Window Name of the active window over time.
I set up a window loop every 5 secs or so to look at each window and then ask if it is active. This seems like too much work for a simple thing. It actually takes more than 5 secs to loop through them all.
It would seem natural to have a system variable that returns the name (handle, etc.) of the then active window. It would also seem natural to have a window watch type trigger event that fires when the state of the active window changes.
Using the new window trigger and new active window name variable, I can trap the deactivation of the active window, look what is active now, and log it along with the date and time.
Have I missed these or is there some simpler way to do what I want?
Thank you in advance.
Great utility!!
Active Window for Application Log
Active Window for Application Log
You can wrote this function yourself. I think that you are able to write a simple BASIC script. See example below. Of course you must have already installed BASIC plugin for RoboTask. If you have any more questions, ask me.
'script begin
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Sub Main
Dim h As Long
Dim capt,clname As String
Dim s As String
h = GetForegroundWindow
capt = Space(255)
clname = Space(255)
GetWindowText(h,capt,255)
GetClassName(h,clname,255)
RoboTaskApp.SetUserVariable("w _h",Str(h))
RoboTaskApp.SetUserVariable("w _capt",capt)
RoboTaskApp.SetUserVariable("w _class",clname)
End Sub
'script end
'script begin
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Sub Main
Dim h As Long
Dim capt,clname As String
Dim s As String
h = GetForegroundWindow
capt = Space(255)
clname = Space(255)
GetWindowText(h,capt,255)
GetClassName(h,clname,255)
RoboTaskApp.SetUserVariable("w _h",Str(h))
RoboTaskApp.SetUserVariable("w _capt",capt)
RoboTaskApp.SetUserVariable("w _class",clname)
End Sub
'script end
Active Window for Application Log
Ah! Thank you. Yes, I experimented with BASIC but did not see any window handling functions. Your function alias solution is the trick. And that can open other doors as well.
Perfect! Thanks!
Perfect! Thanks!
Active Window for Application Log
GetForegroundWindow, GetWindowText, GetClassName is not a BASIC functions. It's a functions of Windows. You can use Windows API functions in your own BASIC scripts. To learn more about WinAPI, refer to Microsoft documentation.
Last edited by Oleg on Fri Dec 24, 2004 9:49 am, edited 1 time in total.