【问题标题】:Calling a powershell function with a global hotkey使用全局热键调用 powershell 函数
【发布时间】:2014-06-15 02:17:33
【问题描述】:

我想通过触发由我的脚本注册和取消注册的全局热键(组合 Ctrl+Shift+F12)来使用我的 Powershell 脚本中的函数。我需要访问由我的脚本创建的 .NET 对象。在伪代码中:

$object_i_need = New-Object SomeClass
register_hotkey "Ctrl+Shift+F12" hotkey_func

function hotkey_func { do_something_with $object_i_need }

wait_for_keypress
unregister_hotkey

这有可能吗?

【问题讨论】:

    标签: powershell scripting hotkeys registerhotkey


    【解决方案1】:

    如果 .Net 对象支持Add_Keydown(如 System.Windows.Forms.Form),您可以执行以下操作...

    $objWhatever.KeyPreview = $True
    $objWhatever.Add_KeyDown({
         if ($_.KeyCode -eq "Enter"){
             hotkey_func{}
          } 
    })
    

    【讨论】:

    • 不幸的是,它没有(它是一个 ProcessInfo 对象)。
    猜你喜欢
    • 2014-05-27
    • 1970-01-01
    • 2022-08-03
    • 2018-12-21
    • 2011-05-01
    • 1970-01-01
    相关资源
    最近更新 更多