Use the PC dll library to implement the function.
This article provides examples of dll library implementation functions for your reference. The specific content is as follows:
ScreenForm. cs code:
Using System; using System. collections. generic; using System. runtime. interopServices; using System. windows. forms; namespace screenT {public partial class ScreenForm: Form {public ScreenForm () {InitializeComponent ();} private void ScreenCapture () {DLL. prScrn ();} protected override void WndProc (ref Message m) {base. wndProc (ref m); Hotkey. processHotKey (m);} private void button#click (object sender, EventArgs e) {DLL. prScrn ();} private void Form1_Load (object sender, EventArgs e) {// register the Hotkey (Form handle, Hotkey ID, secondary key, solid key) try {Hotkey. regist (Handle, HotkeyModifiers. MOD_ALT, Keys. f1, ScreenCapture);} catch (Exception te) {MessageBox. show ("Alt + A Hot Key occupied") ;}} private void form=formclosed (object sender, FormClosedEventArgs e) {// Delete Hotkey (handle, Hotkey ID) Hotkey. unRegist (Handle, ScreenCapture);} public class DLL {[DllImport ("PrScrn. dll ", EntryPoint =" PrScrn ")] public static extern int PrScrn (); // consistent with that in dll} public static class Hotkey {# region system api [DllImport ("user32.dll")] [return: financialas (UnmanagedType. bool)] private static extern bool RegisterHotKey (IntPtr hWnd, int id, HotkeyModifiers fsModifiers, Keys vk); [DllImport ("user32.dll")] private static extern bool partial (IntPtr hWnd, int id ); # Endregion public delegate void HotKeyCallBackHanlder (); private const int WM_HOTKEY = 0x312; private static int keyid = 10; private static readonly Dictionary <int, hotKeyCallBackHanlder> keymap = new Dictionary <int, HotKeyCallBackHanlder> (); /// <summary> /// register the shortcut key /// </summary> /// <param name = "hWnd"> hold the handle of the shortcut key window </param> // /<param name = "fsModifiers"> key combination </param> // <param name = "vk"> virtual key code of the shortcut key </pa Ram> // <param name = "callBack"> callBack function </param> public static void Regist (IntPtr hWnd, HotkeyModifiers fsModifiers, Keys vk, HotKeyCallBackHanlder callBack) {int id = keyid ++; if (! RegisterHotKey (hWnd, id, fsModifiers, vk) throw new Exception ("regist hotkey fail. "); keymap [id] = callBack ;} /// <summary> /// cancel the shortcut key /// </summary> /// <param name = "hWnd"> hold the handle of the shortcut key window </param> // /<param name = "callBack"> callBack function </param> public static void UnRegist (IntPtr hWnd, hotKeyCallBackHanlder callBack) {foreach (var in keymap) {if (var. value = callBack) UnregisterHotKey (hWnd, var. key) ;}//< summary> /// shortcut Key Message processing //</summary> public static void ProcessHotKey (Message m) {if (m. msg = WM_HOTKEY) {int id = m. WParam. toInt32 (); HotKeyCallBackHanlder callback; if (keymap. tryGetValue (id, out callback) {callback () ;}}} public enum HotkeyModifiers {MOD_ALT = 0x1, MOD_CONTROL = 0x2, MOD_SHIFT = 0x4, MOD_WIN = 0x8 }}
Running result:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.