我想让自定义文本始终打印在屏幕上。我尝试使用 rainmeter 软件,但找不到从系统上的文件加载文本的选项或任何其他方式。
我想要的是一款可以在所有窗口顶部打印并每秒扫描文件一次以打印最新更改的软件。
PS 我的想法是每秒或者当新的条目出现时将我的实时 PHP 网站错误日志打印在屏幕上。
答案1
我已经设法让它工作了,但你可能需要调整透明度/字体大小/背景颜色才能让它易于阅读。
您需要安装自动热键并运行此脚本:https://www.dropbox.com/s/x510z8tsxunardl/OSDTest.ahk
代码中有一些注释,但简而言之,它将:从指定的日志文件末尾读取 5 行;创建一个窗口并将其作为文本添加到窗口上;使窗口透明、始终位于顶部并且“不可点击”;并且每 1 秒更新一次文本(可能需要增加这个时间,但我没有看到巨大的性能损失 - 即使日志文件有 20mb)。
要退出脚本,请右键单击系统托盘中的 AutoHotKey 图标并选择退出。
如果我的链接断了,AHK 代码如下:
#SingleInstance force
; Example: On-screen display (OSD) via transparent window:
FileName := "C:\xampplite\apache\logs\access.log"
NumLines = 5
CustomColor = FF8080 ; The transparent background color of the window, set this to something close to your text colour to avoid white highlighting
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow +E0x20 ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s12 ; Set a large font size (12-point).
errorTail := FileTail(FileName , NumLines) ; get the text from the file, last 5 lines
Gui, Add, Text, vMyText cRed Y+0, %errorTail% ; add it, colour is Red, R5 sets 5 rows
; choose one of these lines, first one show just the text, second one has a background for readability
WinSet, TransColor, %CustomColor% 200 ; Make all pixels of this color transparent and make the text itself translucent (250)
;Winset, Transparent, 150
SetTimer, UpdateOSD, 1000 ; 1 second timer set here
Gui, Show, x0 y600 NoActivate ; Set the x and y position. NoActivate avoids deactivating the currently active window.
return
UpdateOSD: ; the repeated timer routine
errorTail := FileTail(FileName, NumLines) ;get 5 lines
GuiControl,, MyText, %errorTail%
return
; ======================================================================================================================
; Function: Retrieve the last lines of a text file.
; AHK version: 1.1.07+
; Parameters:
; FileName - the name of the file, assumed to be in A_WorkingDir if an absolute path isn't specified
; Lines - number of lines to read - default: 10 (like Unix)
; NewLine - new line character(s) - default: `r`n (Windows)
; Return values:
; On success: The required lines, if present
; On failure: ""
; Version: 1.0.00.00/2012-04-16/just me
; ======================================================================================================================
FileTail(FileName, Lines = 10, NewLine = "`r`n") {
Static MaxLineLength := 256 ; seems to be reasonable to start with
If !IsObject(File := FileOpen(FileName, "r"))
Return ""
Content := ""
LinesLength := MaxLineLength * Lines * (InStr(File.Encoding, "UTF-16") ? 2 : 1)
FileLength := File.Length
BytesToRead := 0
FoundLines := 0
While (BytesToRead < FileLength) && !(FoundLines) {
BytesToRead += LinesLength
If (BytesToRead < FileLength)
File.Pos := FileLength - BytesToRead
Else
File.Pos := 0
Content := RTrim(File.Read(), "`r`n")
If (FoundLines := InStr(Content, NewLine, 0, 0, Lines))
Content := SubStr(Content, FoundLines + StrLen(NewLine))
}
File.Close()
Return Content
}