public int RegisterHotkey(Keys Key, KeyFlags keyflags) { UInt32 hotkeyid = NativeMethods.GlobalAddAtom(System.Guid.NewGuid().ToString()); NativeMethods.RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyflags, (UInt32)Key); keyIDs.Add(hotkeyid, hotkeyid); return (int)hotkeyid; }
public int RegisterHotkey(System.Windows.Forms.Keys Key, KeyFlags keyflags) { UInt32 hotkeyid = GlobalAddAtom(System.Guid.NewGuid().ToString()); RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyflags, (UInt32)Key); keyIDs.Add(hotkeyid, hotkeyid); return (int)hotkeyid; }
///<summary> /// 构造函数 ///</summary> ///<param name="win">注册窗体</param> ///<param name="control">控制键</param> ///<param name="key">主键</param> public HotKey(Window win, KeyFlags control, Keys key) { Handle = new WindowInteropHelper(win).Handle; Window = win; ControlKey = (uint)control; Key = (uint)key; KeyId = (int)ControlKey + (int)Key * 10; if (KeyPair.ContainsKey(KeyId)) { throw new Exception("热键已经被注册!"); } if (false == RegisterHotKey(Handle, KeyId, ControlKey, Key)) { throw new Exception("热键注册失败!"); } //消息挂钩只能连接一次!! if (KeyPair.Count == 0) { if (false == InstallHotKeyHook(this)) { throw new Exception("消息挂钩连接失败!"); } } KeyPair.Add(KeyId, this); }
internal KeyAction(SDL.SDL_KeyboardEvent ev) { SDL.SDL_Keymod modifiers = ev.keysym.mod; KeyFlags cflags = KeyFlags.Null; if ((modifiers & SDL.SDL_Keymod.KMOD_SHIFT) != 0) { cflags |= KeyFlags.Shift; } if ((modifiers & SDL.SDL_Keymod.KMOD_ALT) != 0) { cflags |= KeyFlags.Alt; } if ((modifiers & SDL.SDL_Keymod.KMOD_CTRL) != 0) { cflags |= KeyFlags.Ctrl; } if ((modifiers & SDL.SDL_Keymod.KMOD_CAPS) != 0) { cflags |= KeyFlags.CapsLock; } Flags = cflags; Key = MapSDLKeycode(ev.keysym.sym); Repeat = ev.repeat != 0; }
public KeyEventArgs(KeyFlags flags, byte key, byte virtualKey, bool losingFocus) { Flags = flags; Key = key; VirtualKey = virtualKey; LosingFocus = losingFocus; }
public static bool TryImport( Algorithm algorithm, ReadOnlySpan <byte> blob, KeyBlobFormat format, KeyFlags flags, out Key result) { if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; try { success = algorithm.TryImportKey(blob, format, out keyHandle, out publicKeyBytes); } finally { if (!success && keyHandle != null) { keyHandle.Dispose(); } } result = success ? new Key(algorithm, flags, keyHandle, publicKeyBytes) : null; return(success); }
/// <summary> /// 注册热键 /// </summary> public int RegisterHotkey(Keys key, KeyFlags keyflags, HotkeyEventHandler handler) { var hotkeyid = GlobalAddAtom(Guid.NewGuid().ToString()); RegisterHotKey(hWnd, hotkeyid, (uint)keyflags, (uint)key); dictionary.Add(hotkeyid, handler); return((int)hotkeyid); }
public int RegisterHotkey(Keys Key, KeyFlags keyflags) { UInt32 hotkeyid = NativeMethods.GlobalAddAtom(System.Guid.NewGuid().ToString()); NativeMethods.RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyflags, (UInt32)Key); keyIDs.Add(hotkeyid, hotkeyid); return((int)hotkeyid); }
public int RegisterHotkey(Keys Key, KeyFlags keyflags) { uint hotkeyid = GlobalAddAtom(Guid.NewGuid().ToString()); RegisterHotKey(hWnd, hotkeyid, (uint)keyflags, (uint)Key); keyIDs.Add(hotkeyid, hotkeyid); return((int)hotkeyid); }
public Key DeriveKey( SharedSecret sharedSecret, ReadOnlySpan <byte> salt, ReadOnlySpan <byte> info, Algorithm algorithm, KeyFlags flags = KeyFlags.None) { if (sharedSecret == null) { throw Error.ArgumentNull_SharedSecret(nameof(sharedSecret)); } if (!_supportsSalt && !salt.IsEmpty) { throw Error.Argument_SaltNotSupported(nameof(salt)); } if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } int seedSize = algorithm.GetDefaultSeedSize(); if (seedSize > MaxOutputSize) { throw Error.NotSupported_CreateKey(); } SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; Span <byte> seed; try { unsafe { Debug.Assert(seedSize <= 64); byte *pointer = stackalloc byte[seedSize]; seed = new Span <byte>(pointer, seedSize); } DeriveBytesCore(sharedSecret.Handle, salt, info, seed); algorithm.CreateKey(seed, out keyHandle, out publicKeyBytes); success = true; } finally { sodium_memzero(ref seed.DangerousGetPinnableReference(), (UIntPtr)seed.Length); if (!success && keyHandle != null) { keyHandle.Dispose(); } } return(new Key(algorithm, flags, keyHandle, publicKeyBytes)); }
private void checkValue(byte[] flag, int val) { KeyFlags f = new KeyFlags(true, flag); if (f.Flags != val) { Fail("flag value mismatch"); } }
private static int LowLevelKeyboardHookCallback(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam)); } // The wParam in the context of a Low Level Keyboard Hook Procedure is a flag for the type of keyboard event // Differentiating between key presses (and holding the key down), key releases, and key presses and releases with // the alt key pressed down? KeyFlags keyboardMessageIdentifier = (KeyFlags)wParam.ToInt32(); switch (keyboardMessageIdentifier) { case KeyFlags.WM_KEYDOWN: Debug.WriteLine("WM_KEYDOWN"); break; case KeyFlags.WM_KEYUP: Debug.WriteLine("WM_KEYUP"); break; case KeyFlags.WM_SYSKEYDOWN: Debug.WriteLine("WM_SYSKEYDOWN"); break; case KeyFlags.WM_SYSKEYUP: Debug.WriteLine("WM_SYSKEYUP"); break; default: Debug.Fail("Unknown flag: " + keyboardMessageIdentifier); break; } // The lParam in the context of a Low Level Keyboard Hook Procedure is a pointer to a structure called KBDLLHOOKSTRUCT // The structure contains: // a virtual key code // a hardware scan code // flags for: // extended key // event-injection // context code // transition (key up or key down) KeyboardStruct kbs = Marshal.PtrToStructure <KeyboardStruct>(lParam); Keys key = (Keys)kbs.vkCode; Debug.WriteLine(key); Debug.WriteLine(kbs.scanCode); Debug.WriteLine(kbs.flags); Debug.WriteLine(kbs.time); Debug.WriteLine(kbs.dwExtraInfo.ToUInt64()); Debug.WriteLine(""); return(CallNextHookEx(IntPtr.Zero, code, wParam, lParam)); }
public int RegisterHotkey(Keys Key, KeyFlags keyflags) { UInt32 hotkeyid = GlobalAddAtom(Guid.NewGuid().ToString()); RegisterHotKey(hWnd, hotkeyid, (UInt32)keyflags, (UInt32)Key); if (!keyIDs.ContainsKey(hotkeyid)) { keyIDs.Add(hotkeyid, hotkeyid); } return((int)hotkeyid); }
static void SetInfo(Keys key, Char c, KeyFlags flags) { if ((int)key < KeyInfoTable.Length) { KeyInfoTable[(int)key] = (uint)flags | c; } else { KeyInfoMap.Add(key, (uint)flags | c); } }
public static unsafe HotKey Register(byte virtualKey, KeyFlags keyFlags, string description, Action <HotKey> action) { var hotKey = new HotKey(action); hotKey._id = DisplayAPI.RegisterHotKey( virtualKey, keyFlags, description, CallbackHolder.HotKeyCallback, GCHandle.ToIntPtr(hotKey._handle).ToPointer()); return(hotKey); }
public int RegisterHotkey(Key Key, KeyFlags keyflags) { try { UInt32 hotkeyid = GlobalAddAtom(global::System.Guid.NewGuid().ToString()); int keycode = KeyInterop.VirtualKeyFromKey(Key); RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyflags, (UInt32)keycode); keyIDs.Add(hotkeyid, hotkeyid); return((int)hotkeyid); } catch { return(0); }; }
public Key DeriveKey( SharedSecret sharedSecret, ReadOnlySpan <byte> salt, ReadOnlySpan <byte> info, Algorithm algorithm, KeyFlags flags = KeyFlags.None) { if (sharedSecret == null) { throw Error.ArgumentNull_SharedSecret(nameof(sharedSecret)); } if (!_supportsSalt && !salt.IsEmpty) { throw Error.Argument_SaltNotSupported(nameof(salt)); } if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } int keySize = algorithm.GetDefaultKeySize(); if (keySize > MaxOutputSize) { throw Error.NotSupported_CreateKey(); } SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; try { SecureMemoryHandle.Alloc(keySize, out keyHandle); DeriveKeyCore(sharedSecret.Handle, salt, info, keyHandle); algorithm.CreateKey(keyHandle, out publicKeyBytes); success = true; } finally { if (!success && keyHandle != null) { keyHandle.Dispose(); } } return(new Key(algorithm, flags, keyHandle, publicKeyBytes)); }
/// <summary> /// 注册全局热键方法,并把相关信息加入到RegisterdHotKeys /// </summary> /// <param name="keyflags">标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效</param> /// <param name="Key">定义热键的内容</param> /// <param name="name">可定义对应的名称</param> /// <returns>是否注册成功</returns> public bool RegisterHotkey(KeyFlags keyflags, Keys Key, string name = "") { name = name.IsValuable() ? name : Guid.NewGuid().ToString("N"); var hotkeyID = GlobalAddAtom(name); if (RegisterHotKey(hWnd, hotkeyID, keyflags, Key)) { RegisterdHotKeys.Add(hotkeyID, name); return(true); } else { return(false); } }
public void Delete(string path, string name) { var delete = new AnimationSettingsValue <T>(path, name, null); if (delete.Type == MatcherType.Key) { KeyFlags.Remove(delete.Matcher); } if (delete.Type == MatcherType.Path) { PathFlags.Remove(delete.Matcher); } SaveToFile(delete); }
internal Key( Algorithm algorithm, KeyFlags flags, SecureMemoryHandle keyHandle, byte[] publicKeyBytes) { Debug.Assert(algorithm != null); Debug.Assert(keyHandle != null); keyHandle.MakeReadOnly(); _algorithm = algorithm; _flags = flags; _handle = keyHandle; _publicKey = (publicKeyBytes) != null ? new PublicKey(algorithm, publicKeyBytes) : null; }
private string GetFuncKeyAlias(KeyFlags keyFlag) { switch (keyFlag) { case KeyFlags.MOD_ALT: return("ALT"); case KeyFlags.MOD_CONTROL: return("CTRL"); case KeyFlags.MOD_SHIFT: return("SHIFT"); default: return(""); } }
public Key( Algorithm algorithm, KeyFlags flags = KeyFlags.None) { if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } int seedSize = algorithm.GetDefaultSeedSize(); SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; Span <byte> seed; try { unsafe { Debug.Assert(seedSize <= 64); byte *pointer = stackalloc byte[seedSize]; seed = new Span <byte>(pointer, seedSize); } SecureRandom.GenerateBytesCore(seed); algorithm.CreateKey(seed, out keyHandle, out publicKeyBytes); success = true; } finally { sodium_memzero(ref seed.DangerousGetPinnableReference(), (UIntPtr)seed.Length); if (!success && keyHandle != null) { keyHandle.Dispose(); } } keyHandle.MakeReadOnly(); _algorithm = algorithm; _flags = flags; _handle = keyHandle; _publicKey = (publicKeyBytes) != null ? new PublicKey(algorithm, publicKeyBytes) : null; }
public INPUT toINPUT(char key, KeyFlags flag) { return(new INPUT() { Type = 1, Data = new MOUSEKEYBDHARDWAREINPUT() { Keyboard = new KEYBDINPUT() { ExtraInfo = GetMessageExtraInfo(), Flags = (uint)flag, Time = 0, Scan = 0, Vk = (ushort)VkKeyScan(key) } } }); }
public INPUT toINPUT(WindowsVirtualKey key, KeyFlags flag) { return(new INPUT() { Type = 1, Data = new MOUSEKEYBDHARDWAREINPUT() { Keyboard = new KEYBDINPUT() { ExtraInfo = GetMessageExtraInfo(), Flags = (uint)flag, Time = 0, Scan = 0, Vk = (ushort)key } } }); }
private void ChangeQwertyLayout(Container p, int newMode) { p.Suspended = true; foreach (Control key in p.Childs) { if (!(key is TextButton) || key.Tag == null) { continue; } TextButton but = (TextButton)key; KeyFlags flags = (KeyFlags)((int)but.Tag & (int)KeyFlags.TypeMask); if (flags != KeyFlags.NormalKey) { continue; } char keyChar = (char)((int)but.Tag & (int)KeyFlags.KeyMask); int index = 0, row = 0; for (int i = 0; i < 3; i++) { if ((index = Keys[i][_charSetUsed].IndexOf(keyChar)) != -1) { row = i; break; } } if (index == -1) { continue; } char newChar = Keys[row][newMode][index]; but.Text = newChar.ToString(); but.Tag = (int)KeyFlags.NormalKey | ((int)newChar & (int)KeyFlags.KeyMask); but.Enabled = _allowedChars.IndexOf(newChar) >= 0; } _capsButton.Enabled = newMode < 2; _charSetUsed = newMode; p.Suspended = false; }
/// <summary> /// 注册热键构造 /// </summary> /// <param name="win">窗体</param> /// <param name="handle">句柄</param> /// <param name="control">控制键(Ctrl/Alt/Shift/Win等)</param> /// <param name="keycode">键盘虚拟码</param> public HotKey(Window win, IntPtr handle, KeyFlags control, Key keycode) { _Handle = handle; _Window = win; _ControlKey = (int)control; _Key = KeyInterop.VirtualKeyFromKey(keycode); _KeyId = _Key * 10 + _ControlKey; if (DicHotKeys.ContainsKey(_KeyId)) { return; } //---注册热键--- IsRegisterOK = RegisterHotKey(_Handle, _KeyId, _ControlKey, _Key); if (IsRegisterOK && !DicHotKeys.ContainsKey(_KeyId)) { if (HookHotKey(this)) { DicHotKeys.Add(_KeyId, this); } } }
public Key( Algorithm algorithm, KeyFlags flags = KeyFlags.None) { if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } int keySize = algorithm.GetDefaultKeySize(); SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; try { SecureMemoryHandle.Alloc(keySize, out keyHandle); SecureRandom.GenerateKeyCore(keyHandle); algorithm.CreateKey(keyHandle, out publicKeyBytes); success = true; } finally { if (!success && keyHandle != null) { keyHandle.Dispose(); } } keyHandle.MakeReadOnly(); _algorithm = algorithm; _flags = flags; _handle = keyHandle; _publicKey = (publicKeyBytes) != null ? new PublicKey(algorithm, publicKeyBytes) : null; }
public T Load(string path, string name) { var key = GetAnimationKey(path, name); if (KeyFlags.ContainsKey(key)) { return(KeyFlags[key]); } if (PathFlags.ContainsKey(path)) { return(PathFlags[path]); } var match = RegexFlags.FirstOrDefault(x => x.Matcher.IsMatch(key)); if (match != null) { return(match.Value); } return(null); }
private void RemakeAllowedChars(Container p) { p.Suspended = true; foreach (Control key in p.Childs) { if (!(key is TextButton) || key.Tag == null) { continue; } TextButton but = (TextButton)key; KeyFlags flags = (KeyFlags)((int)but.Tag & (int)KeyFlags.TypeMask); if (flags != KeyFlags.NormalKey) { continue; } char keyChar = (char)((int)but.Tag & (int)KeyFlags.KeyMask); but.Enabled = _allowedChars.IndexOf(keyChar) >= 0; } p.Suspended = false; }
public int RegisterHotkey(Keys key) { KeyFlags keyFlags = KeyFlags.MOD_NONE; if ((key & Keys.Shift) == Keys.Shift) { keyFlags = keyFlags | KeyFlags.MOD_SHIFT; } if ((key & Keys.Control) == Keys.Control) { keyFlags = keyFlags | KeyFlags.MOD_CONTROL; } if ((key & Keys.Alt) == Keys.Alt) { keyFlags = keyFlags | KeyFlags.MOD_ALT; } key = key & Keys.KeyCode; UInt32 hotkeyid = GlobalAddAtom(System.Guid.NewGuid().ToString()); RegisterHotKey((IntPtr)hWnd, hotkeyid, (UInt32)keyFlags, (UInt32)key); keyIDs.Add(hotkeyid, hotkeyid); return((int)hotkeyid); }
public void SetBinding(Key key, KeyFlags flags) { bindedKey = key; bindedFlags = flags; canBuild = true; }
private static extern bool CryptGenKey(KeyContainerHandle hProv, AlgorithmType algId, KeyFlags dwFlags, out KeyHandle phKey);
//注册新的热键 public void RegisterHotkey(Keys Key, KeyFlags keyflags) { //为热键生成一个全局唯一标识符 keyID = GlobalAddAtom(System.Guid.NewGuid().ToString()); RegisterHotKey((IntPtr) hWnd, keyID, (UInt32) keyflags, (UInt32) Key); }
extern static bool CryptGenKey( KeyContainerHandle hProv, AlgorithmType algId, KeyFlags dwFlags, [Out]out KeyHandle phKey);