屏幕保护程序激活时切换 SCROLL LOCK [英] Toggle SCROLL LOCK when screensaver activates

查看:28
本文介绍了屏幕保护程序激活时切换 SCROLL LOCK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望制作一个在窗口中始终在后台运行的应用程序,当我的计算机的屏幕保护程序启用时,它会切换滚动锁定,如果可能,然后在它禁用后将其切换回来.

I wish to make an application that runs in the background at all times in windows that toggles scroll lock when my computer's screensaver enables, then toggle it back after it disables, if possible.

原因是我的键盘会根据滚动锁定灯的状态点亮.不使用时让键盘自动关闭灯会很酷.

The reason is that I have a keyboard that lights up depending on the state of the scroll lock light. It would be cool to have the keyboard turn off the lights automatically when im not using it.

我知道一些 VBscript 代码,一些 Python 代码,还有很多 VB 代码.我尝试使用 this 并将其变成这样:

I know some code in VBscript, some in Python, and lots in VB. I have tried using a code snippet from this and turning it into this:

strComputer = "computername"
Set wshShell =wscript.CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")

Do
  WScript.Sleep 300
  For Each objProcess In colProcesses
    If Right(objProcess.Name, 4) = ".scr" Then
      wshShell.SendKeys "{SCROLLLOCK}"
    End If 
  Next
Loop

仅当程序在屏幕保护程序已打开时运行时才有效.请帮助我了解如何在屏幕保护程序打开的情况下每 300 滴答进行一次检查,或者告诉我如何使用标题中列出的其他语言之一进行检查.

which works only if the program runs when the screensaver is already on. Please help me find out how I can make this check every 300 ticks if the screensaver is on, or tell me how in one of the other languages listed in the title.

推荐答案

WMI 查询的结果反映了查询运行时的状态.它不会自动刷新,因此不会选择在初始运行后启动的任何进程.将查询移到外循环内,以便在每次迭代时重新运行:

The result of a WMI query reflects the state when the query was run. It doesn't automatically refresh and thus won't pick up any processes that were launched after its initial run. Move the query inside the outer loop so it's re-run with every iteration:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Do
  WScript.Sleep 300
  Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
  For Each objProcess In colProcesses
    If Right(objProcess.Name, 4) = ".scr" Then
      wshShell.SendKeys "{SCROLLLOCK}"
    End If 
  Next
Loop

这篇关于屏幕保护程序激活时切换 SCROLL LOCK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆