简体   繁体   English

如何在记事本++中创建“即时消息”-VBScript

[英]How to Create “Instant Messaging” in Notepad++ - VBScript

As a past time with a couple of friends, I'm trying to make a sort of "instant messaging" through notepad++. 作为过去与几个朋友在一起的时间,我正在尝试通过notepad ++进行某种“即时消息传递”。

The setup is as follows: Three computers are connected on a network. 设置如下:网络上连接了三台计算机。 On computer 2, there is Notepad++ in its directory. 在计算机2上,其目录中有Notepad ++。 On computer 3, there is the VBScript and the text file (which is opened in Notepad++). 在计算机3上,有VBScript和文本文件(已在Notepad ++中打开)。 The "F5" key in Notepad++ has been rebound to "Reload From Disk" respectively. Notepad ++中的“ F5”键已分别回弹到“从磁盘重新加载”。

The goal is to have Notepad++ refresh every 2 seconds or so, but exclusively in Notepad++, even in the background. 目标是让Notepad ++每2秒左右刷新一次,但只能在Notepad ++中刷新,即使在后台也是如此。 The VBScript is meant to close upon Notepad++ closing. VBScript旨在在Notepad ++关闭时关闭。

The VBScript is as follows (keep in mind I have no prior experience with VBScripts; expect major flaws): VBScript如下(请记住,我以前没有使用VBScript的经验;预计会有重大缺陷):

strFileName = "\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++"  
Dim oShell

set oShell = CreateObject("wScript.Shell")  
oShell.Run "notepad++ ""\\08-111099-CISCO\Users\Javorsky.G\Downloads\New Text Document.txt"""  
oShell.AppActivate "\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++\notepad++.exe"  
Do    
    WScript.Sleep 500  
    oShell.SendKeys "{F5}"  
    wScript.Sleep 2000  
Loop Until Quit  

Notepad++ will open the text file and will begin the F5 loop. Notepad ++将打开文本文件,并开始F5循环。 However, the F5 will continue regardless if Notepad++ is the active window or not, and the script does not close upon Notepad++ closing. 但是,无论Notepad ++是否为活动窗口,F5都将继续运行,并且在Notepad ++关闭时脚本不会关闭。

I'm certainly missing something, but after several hours of research and experimenting, I couldn't find a solution. 我当然会缺少一些东西,但是经过几个小时的研究和实验,我找不到解决方案。

Is it possible to achieve these results with just a VBScript? 仅使用VBScript是否有可能获得这些结果?

AppActivate() returns True if the call was successful (if it found and activated the window). 如果调用成功(如果找到并激活了窗口),则AppActivate()返回True Use that return value to determine whether to continue refreshing or to close your script. 使用该返回值来确定是继续刷新还是关闭脚本。

Do While oShell.AppActivate("\\08-111096-CISCO\Users\Straka.J\Downloads\Notepad++\notepad++.exe")

    oShell.SendKeys "{F5}"
    WScript.Sleep 2000

Loop

' Script exit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM