在不中断当前应用程序的情况下不关注热键的情况 [英] HotKeys when not focused without interupting current application

查看:79
本文介绍了在不中断当前应用程序的情况下不关注热键的情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

好的,很难在主题上进行总结,但是我正在做的atm是一个mp3播放器,可以让我无需集中精力即可更改歌曲.这是因为我经常玩游戏,听音乐,并且时不时地想切换歌曲.当前正在使用Spotify,但它不允许我这样做-因此我想自己做即可.

现在,我已经设法使用教程项目编写了一些内容,因此我确实可以劫持Ctrl + 4之类的按钮,但是如果游戏需要在游戏中无法执行的特定按钮组合,那就可以了.蚂蚁使它起作用,而不管..

基本上,我猜是键盘记录器的工作方式.因此,我只是借用"了按键,而不是直接盗用它.

Hi!

Okay so it was kind of hard to summarize in topic but what I''m doing atm is an mp3 player that will allow me to change songs without having it focused. This is because I am often playing games and listening to music and every now and then i want to switch songs. Currently using spotify and it wont allow me to do it - so I figured I''d do it myself.

Now I''ve managed to write something using a tutorial project so i can indeed hijack a button like Ctrl + 4 or whatever but thing is if the game requires that particular combination of buttons it wont execute in the game.. Which sucks since Iw ant to make it so it functions regardless..

Basically, the way a keylogger works I guess. So I just "borrow" the keystroke and not straight up steal it.

Ideas?

推荐答案

请参阅初学者的教程-使用全局热键 [ ^ ]

我在9年前写过这篇文章,但我相信这些概念应该仍然相同. [除非他们在最新版本的框架中添加了完全托管的类]

[更新]
-------------

好吧,我的坏.我刚刚意识到这篇文章纯粹是针对本机C ++的.这些API需要通过C#进行P/调用.我相信您可以做到这一点.

[Update-2]
-------------

以下是一些示例P/Invoke代码: http://www.pinvoke.net/default.aspx /user32/RegisterHotKey.html [ ^ ]
See Beginner''s Tutorial - Using global hotkeys[^]

I wrote that 9 years ago, but I believe the concepts should still be the same. [unless they added a fully managed class in the framework in recent versions]

[Update]
-------------

Okay, my bad. I just realized that article is purely for native C++. The APIs will need to be P/Invoked from C#. I trust you can do that part.

[Update-2]
-------------

Here''s some sample P/Invoke code: http://www.pinvoke.net/default.aspx/user32/RegisterHotKey.html[^]


您需要劫持任何东西才能处理按键.您没有标记要使用的库(Forms,WPF?),因此不可能给出一个通用答案.而且我不想列出所有可想到的变量.您只需处理KeyDown事件和一些控件,就可以轻松实现所需的全部功能.您还可以使用菜单热键-无论当前关注什么控件,它们都将起作用.



将问题标记为:
使用System.Windows.Forms,您还可以使用System.Windows.Forms.Form.KeyPreview,请参见 http: //msdn.microsoft.com/zh-CN/library/system.windows.forms.form.keypreview.aspx [
You need to hijack anything to just process the keystroke. You did not tag what library you want to use (Forms, WPF?), so it is not possible to give one universal answer; and I don''t want to list all thinkable variable. You can easily achieve all you need by just handling KeyDown event an some controls. You can also use menu hot keys — they will work regardless what control is currently focused.



After the question was tagged:
With System.Windows.Forms, you can also use System.Windows.Forms.Form.KeyPreview, see http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview.aspx[^]. If you assign the valued for this property to true (while default it false), you will be able to process keyboard events before they go to controls; this is what you need.

—SA


这篇关于在不中断当前应用程序的情况下不关注热键的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆