Tecla de acceso rápido global en la aplicación de consola
¿Alguien sabe cómo usar las llamadas API RegisterHotKey / UnregisterHotKey en una aplicación de consola? Supongo que configurar / eliminar la tecla de acceso rápido es lo mismo, pero ¿cómo puedo recuperar la llamada cuando se presionó la tecla?
Cada ejemplo que veo es para Winforms y usaprotected override void WndProc(ref Message m){...}
, que no está disponible para mí.
SetupHotkey
en un hilo diferente no pasa nada. ¿Alguna idea?class Program
{
static void Main(string[] args)
{
new Hud().Init(args);
}
}
class Hud
{
int keyHookId;
public void Init(string[] args)
{
SetupHotkey();
InitPowershell(args);
Cleanup();
}
private void Cleanup()
{
HotKeyManager.UnregisterHotKey(keyHookId);
}
private void SetupHotkey()
{
keyHookId = HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Control);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
}
void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
//never executed
System.IO.File.WriteAllText("c:\\keyPressed.txt", "Hotkey pressed");
}
private static void InitPowershell(string[] args)
{
var config = RunspaceConfiguration.Create();
ConsoleShell.Start(config, "", "", args);
}
}