[FUNC]为AutoHotkey写个print函数替代msgbox大法

105 篇文章 5 订阅
92 篇文章 3 订阅

【方法一】学用AutoHotkey的可能不习惯没有print函数吧,输出都用msgbox有些怪怪的,下面我就为使用Scite4AutoHotkey的用户写个print函数,请将此函数另存到你的lib目录,命名为print.ahk即可,不用引用而直接使用了。

 

print(text)
{
	oSciTE:= ComObjActive("SciTE4AHK.Application")
	oSciTE.Output(text)
}

输出你好的效果如下

 

【清屏】

scite可以支持输出区清屏的,
SciObj := ComObjActive("SciTE4AHK.Application") ;get pointer to active SciTE window
 
SendMessage,SciObj.Message(0x111,420)
SciTE_Output("hello中国")
SciTE_Output("计算式1+1=" . 1+1,0,0)
SciTE_Output("计算式1+1=" . 1+1,0,1,1)
return

;https://autohotkey.com/boards/viewtopic.php?f=7&t=20397
SciTE_Output(Text,Clear=1,LineBreak=1,Exit=0){
SciObj := ComObjActive("SciTE4AHK.Application") ;get pointer to active SciTE window
IfEqual,Clear,1,SendMessage,SciObj.Message(0x111,420) ;If clear=1 Clear output window
IfEqual, LineBreak,1,SetEnv,Text,`r`n%text% ;If LineBreak=1 prepend text with `r`n
SciObj.Output(Text) ;send text to SciTE output pane
IfEqual, Exit,1,MsgBox, 36, Exit App?, Exit Application? ;If Exit=1 ask if want to exit application
IfMsgBox,Yes, ExitApp ;If Msgbox=yes then Exit the appliciation
}

 

【方法二】网友写的调用cmd.exe来显示输出信息的:

F4::
    a:=10
    输出(a)
    输出(a+10)
    输出(a*10)
return

    ; OutputDebug, %内容%
    

清空(){
	ControlSend,,cls`r,ahk_class ConsoleWindowClass
}
输出(内容){
	if(WinExist("ahk_class ConsoleWindowClass")=0)
	{
		Run,cmd.exe
		sleep 500
	}
	ControlSend,,::%内容%`r,ahk_class ConsoleWindowClass
}

【推荐方法】:用ahk内置命令OutputDebug来调试,需下载debugview工具:

 

https://github.com/CobaltFusion/DebugViewPP
DebugView 的增强版本。可以捕捉指定进程、含命令行版本。

 

在ahk脚本中用OutputDebug命令来输出调试信息,命令形式如下:
OutputDebug,想要输出的字符串

    F4::
        a:=10
        输出(a)
        输出(a+10)
        输出(a*10)
    return
     输出(内容){
         OutputDebug, %内容%
       } 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值