4

I want to use a function from my Powershell script by triggering a global hotkey (the combination Ctrl+Shift+F12) which is registered and unregistered by my script. I need to access a .NET object created by my script. In pseudo code:

$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

Is this possible somehow?

4

1 回答 1

0

如果 .Net 对象支持Add_Keydown(如 System.Windows.Forms.Form),你可以做这样的事情......

$objWhatever.KeyPreview = $True
$objWhatever.Add_KeyDown({
     if ($_.KeyCode -eq "Enter"){
         hotkey_func{}
      } 
})
于 2014-04-29T14:04:19.033 回答