本文介绍了在PowerShell中检测跨应用程序的按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个可以通过Wayback机器在Powershell.com上找到的帖子。它是2015年的,现在已经不在网站上了。指向它的链接在此处:Detecting Key Presses Across Applications

此帖子旨在存档。

推荐答案

#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中检测跨应用程序的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 15:36