C#获取全局键盘笔划?

编程入门 行业动态 更新时间:2024-10-28 02:22:30
本文介绍了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/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx [ ^ ], msdn.microsoft/en-us/ library / windows / desktop / ms646327(v = vs.85).aspx [ ^ ]。 至于P / Invoke使用,它已经为你完成了: www.pinvoke/default。 aspx / user32.registerhotkey [ ^ ], www.pinvoke/default.aspx/user32.unregisterhotkey [ ^ ]。 享受!
-SA
If you really need to use system-wide hot keys, raw Windows API does it for you. Please see: msdn.microsoft/en-us/library/windows/desktop/ms646309%28v=vs.85%29.aspx[^], msdn.microsoft/en-us/library/windows/desktop/ms646327(v=vs.85).aspx[^]. As to the P/Invoke use, it's already done for you: www.pinvoke/default.aspx/user32.registerhotkey[^], www.pinvoke/default.aspx/user32.unregisterhotkey[^]. Enjoy!
—SA

更多推荐

C#获取全局键盘笔划?

本文发布于:2023-11-08 10:47:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1569173.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   笔划   键盘

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!