分享

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

 dinghj 2019-04-14

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

 

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

输出你好的效果如下

 

【清屏】

  1. scite可以支持输出区清屏的,
  2. SciObj := ComObjActive("SciTE4AHK.Application") ;get pointer to active SciTE window
  3. 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:///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来显示输出信息的:

  1. F4::
  2. a:=10
  3. 输出(a)
  4. 输出(a+10)
  5. 输出(a*10)
  6. return
  7. ; OutputDebug, %内容%
  8. 清空(){
  9. ControlSend,,cls`r,ahk_class ConsoleWindowClass
  10. }
  11. 输出(内容){
  12. if(WinExist("ahk_class ConsoleWindowClass")=0)
  13. {
  14. Run,cmd.exe
  15. sleep 500
  16. }
  17. ControlSend,,::%内容%`r,ahk_class ConsoleWindowClass
  18. }

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

 

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

 

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

  1. F4::
  2. a:=10
  3. 输出(a)
  4. 输出(a+10)
  5. 输出(a*10)
  6. return
  7. 输出(内容){
  8. OutputDebug, %内容%
  9. }

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多