如何使用密钥作为公共密钥 [英] How to use the Key as public key

查看:117
本文介绍了如何使用密钥作为公共密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Altr + A作为保存键.就像用户按Altr + A键一样,条目将保存.

我想编写为公共函数,以便用户在输入模式下随时按此Altr + A键将保存输入.我想获取此密钥.


最好的问候,
Jatinder Gupta.

I want to use the i.e Altr+A as a save key. Like if the user press the Key Altr+A the entries become save.

I want to write as public function so that user will press this Altr+A key at any time in a Entry mode will save the entry. I want to capture this key.


Best regards,
Jatinder Gupta.

推荐答案

对不起...您只是在说要在WinForms项目中使用快捷方式吗?

您没有说,但是如果这是Windows Forms应用程序,则可以轻松设置快捷键.

如果已经设置菜单,请转到保存菜单"项并设置其ShortcutKeys属性.

或者,您可以挂钩表单的KeyDown并检查Alt + A,然后运行保存例程. (KeyDown使用KeyEventArgs,它具有Control和Alt属性,您可以检查它们是否被按下).
Sorry...are you simply saying that you want to have a shortcut in your WinForms project?

You didn''t say, but if this is a Windows Forms application, then you can easily set up a shortcut key.

If you already have menus set up, then go to your Save Menu item and set it''s ShortcutKeys property.

Alternatively, you could hook the form''s KeyDown and check for Alt+A and then run your save routine. (KeyDown uses KeyEventArgs which has a Control and Alt property that you can check to see if they''re pressed).



您可以从以下链接获得帮助:
Hi,
You can get the help from following link:
//Key:   http://msdn.microsoft.com/en-us/library/ms927178.aspx<br />
       //Code:  http://social.msdn.microsoft.com/forums/en-US/vbgeneral<br />




常规GlobalHotkey类




General GlobalHotkey class

public class GlobalHotkeys
    {
        //Virtual-Key Codes
        //Key:   http://msdn.microsoft.com/en-us/library/ms927178.aspx
        //Code:  http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/5197e0ee-ef85-4f9e-8652-631b8a80e330/
        //The following table shows the symbolic constant names, hexadecimal values,
        //and keyboard equivalents for the virtual-key codes used by the Microsoft Windows CE operating system.
        //The codes are listed in numeric order.
        //You can combine any of the codes with a modifier key to create a hot key.
        //----------------------------------------------------------------------------------------
        //Symbolic constant Hexadecimal     Mouse or keyboard equivalent
        //----------------------------------------------------------------------------------------
        //VK_LBUTTON        01              Left mouse button
        //VK_RBUTTON        02              Right mouse button
        //VK_CANCEL         03              Control-break processing
        //VK_MBUTTON        04              Middle mouse button on a three-button mouse
        //VK_BACK           08              BACKSPACE key
        //VK_TAB            09              TAB key
        //VK_CLEAR          0C              CLEAR key
        //VK_RETURN         0D              ENTER key
        //VK_SHIFT          10              SHIFT key
        //VK_CONTROL        11              CTRL key
        //VK_MENU           12              ALT key
        //VK_PAUSE          13              PAUSE key
        //VK_CAPITAL        14              CAPS LOCK key
        //VK_ESCAPE         1B              ESC key
        //VK_SPACE          20              SPACEBAR
        //VK_PRIOR          21              PAGE UP key
        //VK_NEXT           22              PAGE DOWN key
        //VK_END            23              END key
        //VK_HOME           24              HOME key
        //VK_LEFT           25              LEFT ARROW key
        //VK_UP             26              UP ARROW key
        //VK_RIGHT          27              RIGHT ARROW key
        //VK_DOWN           28              DOWN ARROW key
        //VK_SNAPSHOT       2C              PRINT SCREEN key
        //VK_INSERT         2D              INS key
        //VK_DELETE         2E              DEL key
        //VK_HELP           2F              HELP key
        //VK_NUMPAD0        60              Numeric keypad 0 key
        //VK_NUMPAD1        61              Numeric keypad 1 key
        //VK_NUMPAD2        62              Numeric keypad 2 key
        //VK_NUMPAD3        63              Numeric keypad 3 key
        //VK_NUMPAD4        64              Numeric keypad 4 key
        //VK_NUMPAD5        65              Numeric keypad 5 key
        //VK_NUMPAD6        66              Numeric keypad 6 key
        //VK_NUMPAD7        67              Numeric keypad 7 key
        //VK_NUMPAD8        68              Numeric keypad 8 key
        //VK_NUMPAD9        69              Numeric keypad 9 key
        //VK_MULTIPLY       6A              Multiply key
        //VK_ADD            6B              Add key
        //VK_SEPARATOR      6C              Separator key
        //VK_SUBTRACT       6D              Subtract key
        //VK_DECIMAL        6E              Decimal key
        //VK_DIVIDE         6F              Divide key
        //VK_F1             70              F1 key
        //VK_F2             71              F2 key
        //VK_F3             72              F3 key
        //VK_F4             73              F4 key
        //VK_F5             74              F5 key
        //VK_F6             75              F6 key
        //VK_F7             76              F7 key
        //VK_F8             77              F8 key
        //VK_F9             78              F9 key
        //VK_F10            79              F10 key
        //VK_F11            7A              F11 key
        //VK_F12            7B              F12 key
        //VK_F13            7C              F13 key
        //VK_F14            7D              F14 key
        //VK_F15            7E              F15 key
        //VK_F16            7F              F16 key
        //VK_F17            80H             F17 key
        //VK_F18            81H             F18 key
        //VK_F19            82H             F19 key
        //VK_F20            83H             F20 key
        //VK_F21            84H             F21 key
        //VK_F22            85H             F22 key(PPC only) Key used to lock device.
        //VK_F23            86H             F23 key
        //VK_F24            87H             F24 key
        //VK_NUMLOCK        90              NUM LOCK key
        //VK_SCROLL         91              SCROLL LOCK key
        //VK_LSHIFT         0xA0            Left SHIFT
        //VK_RSHIFT         0xA1            Right SHIFT
        //VK_LCONTROL       0xA2            Left CTRL
        //VK_RCONTROL       0xA3            Right CTRL
        //VK_LMENU          0xA4            Left ALT
        //VK_RMENU          0xA5            Right ALT
        #region Enum
        public enum Key
        {
            NumpadDecimal = 1,
            NumpadMultiply,
            Escape,
            End,
            CtrlR,
            CtrlF,
            CtrlC,
            CtrlI
            /*NumpadEnter,
            NumpadDelete,
            NumpadSubtract,
            NumpadAdd,
            NumpadD1,
            NumpadD2,
            NumpadD3,
            NumpadD4,
            NumpadD5,
            NumpadD6,
            NumpadD7,
            NumpadD8,
            NumpadD9*/
        }
        public enum SymbolicKey
        {
            None = 0,
            Alt = 1,
            Ctrl = 2,
            Shift = 4
        }
        #endregion
        #region fields
        //DEL key
        public const int VK_DECIMAL = 0x6e;
        //Multiply key
        public const int VK_MULTIPLY = 0x6a;
        //Alt key
        //public static int MOD_ALT = 0x1;
        //public static int MOD_CONTROL = 0x2;
        //public static int MOD_SHIFT = 0x4;
        public static int MOD_WIN = 0x8;
        public static int WM_HOTKEY = 0x312;
        //public static int MOD_NONE = 0x0;
        //private static int keyId;
        #endregion
        [DllImport("user32.dll")]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
        [DllImport("user32.dll")]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
}




在表单加载时注册热键




Register HotKey on form load

private void frmMain_Load(object sender, EventArgs e)
        {
            GlobalHotkeys.RegisterHotKey(this.Handle, Convert.ToInt32(GlobalHotkeys.Key.NumpadDecimal), Convert.ToInt32(GlobalHotkeys.SymbolicKey.None), Convert.ToInt32(Keys.Decimal));
}



在表单关闭时取消注册热键



UnRegister HotKey on form closing

private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
       {
           GlobalHotkeys.UnregisterHotKey(this.Handle, Convert.ToInt32(GlobalHotkeys.Key.NumpadDecimal));
}


这篇关于如何使用密钥作为公共密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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