C#获取全局键盘笔划? [英] C# Get Global Keyboard Stroke?

查看:151
本文介绍了C#获取全局键盘笔划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone again!

当我按下一个键组合(如CTRL + E或其他东西)时,我有一个想法可以最小化或关闭我的应用程序。现在我知道如何最小化和关闭应用程序,我可以使用使用DestroyWindow方法的win api或CloseWindow(这是为了最小化应用程序)方法这样做

i也希望能够按CTRl + B或某种键组合并将应用程序带到窗口堆栈的前面(或窗口链或其他任何调用)我可以通过调用windows api中的BringWindowToTop方法来实现这一点

我不知道怎么办是当我全局按下键盘组合时如何告诉我的应用程序执行这些功能,或者我应该说当我的应用程序有焦点时。

i有一个感觉我将指的是这个工作的win api和User32.dll方法列表吗?(Gosh我讨厌使用P / Invoke,它使用无人C ++这么复杂)

对于函数我想做(比如最小化窗口并将其带到前面)我导入了以下方法:

Hello Everyone again!
i had an idea to minimize or close my app when i press a key combo(like CTRL+E or something). Now i know how to minimize and close the app, i can do that either using the win api using the DestroyWindow method or the CloseWindow(this is to minimize the app) method
i also want to be able to press CTRl+B or some sort of key combo and bring the app to the front of the window stack(or window chain or whatever its called) i can do this by calling the BringWindowToTop method in the windows api
what i don't know how to do is how do i tell my app to execute those functions when a keyboard combo is pressed globally, or i should say when my app has focus or not.
i have a felling i will be referring to the win api and the User32.dll method list for this job right?(Gosh i hate using P/Invoke, its so complicated to use unmanned C++)
For the functions i want to do(like minimizing the window and bringing it to the front) i have imported the following methods:

[DllImport("user32.dll")]
using System.Runtime.InteropServices;
public static extern void DestroyWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern void CloseWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern void BringWindowToTop(IntPtr hWnd);



感谢所有人提前帮助,

MasterCodeon


thanks for all of your help in advance,
MasterCodeon

推荐答案

如果您确实需要使用系统范围的热键,原始Windows API会为您完成。请参阅:

http ://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx [ ^ ],

< a href =http://msdn.microsoft.com/en-us/library/windows/desktop/ms646327(v=vs.85).aspx> http://msdn.microsoft.com/en-us/ library / windows / desktop / ms646327(v = vs.85).aspx [ ^ ]。



至于P / Invoke使用,它已经为你完成了:

http://www.pinvoke.net/default。 aspx / user32.registerhotkey [ ^ ],

http://www.pinvoke.net/default.aspx/user32.unregisterhotkey [ ^ ]。



享受!



-SA
If you really need to use system-wide hot keys, raw Windows API does it for you. Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646327(v=vs.85).aspx[^].

As to the P/Invoke use, it's already done for you:
http://www.pinvoke.net/default.aspx/user32.registerhotkey[^],
http://www.pinvoke.net/default.aspx/user32.unregisterhotkey[^].

Enjoy!

—SA


这篇关于C#获取全局键盘笔划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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