gpt4 book ai didi

powershell - 在Powershell中检测跨应用程序的按键

转载 作者:行者123 更新时间:2023-12-03 01:07:21 25 4
gpt4 key购买 nike

这是可以通过Wayback机器在Powershell.com上找到的帖子。它是从2015年开始的,不再在网站上。
链接到这里:Detecting Key Presses Across Applications

该帖子旨在成为存档。

最佳答案

By accessing the Windows low-level system calls, PowerShell can query the keyboard for pressed keys. The following example waits until the user presses 'A'. This is a simple example that does not consider the state of the SHIFT keys, nor does it check virtual keys. However, it detects key presses across all open applications. So PowerShell will detect a pressed "A" key even if it does not have focus, and you entered "A" into a different application.


#requires -Version 2

$signature = @'
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern short GetAsyncKeyState(int virtualKeyCode);
'@

# load signatures and make members available
$API = Add-Type -MemberDefinition $signature -Name 'Keypress' -Namespace API -PassThru

# wait for 'A'
$waitFor = 'A'
$ascii = [byte][char]$waitFor.ToUpper()

do
{
Start-Sleep -Milliseconds 40
} until ($API::GetAsyncKeyState($ascii) -eq -32767)

关于powershell - 在Powershell中检测跨应用程序的按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46010963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com