使用其他程序时如何使用keybinds(由c#表单定制)?

问题描述 投票:-1回答:3

我创建了一个表格,我有一个bind "f4" for pausing music。当我使用另一个程序时,我可以使用keybind但only when I am using the form,即。谷歌Chrome,and attempted to use f4 for pausing music, the program ignores my key's responds

如何在使用其他程序时让我的表单响应我的键盘?

c# winforms
3个回答
0
投票

希望现在有一个更好的解决方案,但我总是在计时器上使用Win32的GetAsyncKeyState完成此操作。 Import code and Samples


0
投票

正常的键绑定仅在程序具有焦点时触发。而是看看https://www.fluxbytes.com/csharp/how-to-register-a-global-hotkey-for-your-application-in-c/


0
投票

您可以使用Keyboard Hooks执行类似的操作。不幸的是,代码是旧的本机代码。您必须从托管应用程序调用非托管代码。

我尽量避免使用非托管代码,但对于你来说,它可能是一个选项:qazxsw poi

© www.soinside.com 2019 - 2024. All rights reserved.