Пример #1
0
 private void Fire_SystemKeyDown(KeyboardHookEventArgs kea)
 {
     if (SystemKeyDown != null)
     {
         SystemKeyDown(this, kea);
     }
 }
Пример #2
0
 private void Fire_KeyUp(KeyboardHookEventArgs kea)
 {
     if (KeyUp != null)
     {
         KeyUp(this, kea);
     }
 }
Пример #3
0
 void keyDown(object sender, KeyboardHookEventArgs e)
 {
     if (e.KeyboardState == KeyboardHook.KeyboardState.KeyDown && e.KeyboardData.VirtualCode == 0x72)   //F3 virtual code
     {
         (new OptionsForm()).ShowDialog();
     }
 }
Пример #4
0
        private static void Hook_KeyDown(object sender, KeyboardHookEventArgs e)
        {
            IntPtr activeWnd = UnsafeNativeMethods.GetForegroundWindow();
            IntPtr focus     = UnsafeNativeMethods.GetFocus();

            foreach (var hk in GetAvailableHotkey())
            {
                // 핫키 보조키와 눌린 보조키가 없거나, 있는경우 마지막 키코드가 보조키여서는 안됨.
                // 핫키 대상이 글로벌이거나, 아닌경우 대상과 일치하는지 확인.
                if (((!hk.HasModifierKey && Keyboard.ModifierKeys == VKeys.None) ||
                     (hk.HasModifierKey && !Keyboard.IsModifierKey(e.KeyCode))) &&
                    (hk.IsGlobal || (!hk.IsGlobal && (hk.Target == activeWnd || hk.Target == focus))))
                {
                    var arg = new HotkeyEventArgs(activeWnd);
                    if (hk.Target == focus && focus != IntPtr.Zero)
                    {
                        arg.Target = focus;
                    }

                    syncContext.Send((o) => hk.Action?.Invoke(hk, arg), null);

                    if (arg.Handled && !hk.HasModifierKey && hk.SubKeys.Contains(e.KeyCode))
                    {
                        e.Handled = true;
                    }
                    else
                    {
                        e.Handled = arg.Handled;
                    }
                }
            }
        }
Пример #5
0
        private void kHook_KeyDown(object sender, KeyboardHookEventArgs e)
        {
            switch (e.KeyString)
            {
            case "[LShiftKey]":
                _activeModifier = _activeModifier.Add(ModifierKey.Shift);
                break;

            case "[LControlKey]":
                _activeModifier = _activeModifier.Add(ModifierKey.Ctrl);
                break;

            case "[LMenu]":
                _activeModifier = _activeModifier.Add(ModifierKey.Alt);
                break;

            case "\\":
                _activeModifier = _activeModifier.Add(ModifierKey.Console);
                break;

            default:
                ProcessKey(e.Char);
                break;
            }
        }
Пример #6
0
        protected virtual int KeyboardHookProc(int code, int wParam, ref Native.keyboardHookStruct lParam)
        {
            if (code >= 0 && KeyboardHookEvent != null)
            {
                var key = (Keys)lParam.vkCode;
                KeyboardEventType type;

                if ((wParam == (int)User32.WM.WM_KEYDOWN || wParam == (int)User32.WM.WM_SYSKEYDOWN))
                {
                    type = KeyboardEventType.KeyDown;
                }
                else if ((wParam == (int)User32.WM.WM_KEYUP || wParam == (int)User32.WM.WM_SYSKEYUP))
                {
                    type = KeyboardEventType.KeyUp;
                }
                else
                {
                    return(Native.CallNextHookEx(_hookId, code, wParam, ref lParam));
                }

                var args = new KeyboardHookEventArgs(type, key, wParam, lParam);
                KeyboardHookEvent(args);

                if (args.Handled)
                {
                    return(1);
                }
            }

            return(Native.CallNextHookEx(_hookId, code, wParam, ref lParam));
        }
Пример #7
0
 private void KeyDown(KeyboardHookEventArgs e)
 {
     if (e.Key == Keys.Q && e.isCtrlPressed)
     {
         _fireOnKeyMatch?.Invoke();
     }
 }
Пример #8
0
        private void KeyDownHandler(KeyboardHookEventArgs e)
        {
            Log.Verbose().Write("KeyDownEvent Recognized.");
            // handle keydown event here
            // Such as by checking if e (KeyboardHookEventArgs) matches the key you're interested in
            Keys userHotKey;

            Enum.TryParse <Keys>(_settings.HotKey, out userHotKey);

            // helper variables:
            // get the modifier settings from settings class and evaluate if they match the
            // current pressed buttons
            var isCtrlModifierValid  = _settings.UseCtrlKey == e.isCtrlPressed ? true : false;
            var isShiftModifierValid = _settings.UseShiftKey == e.isShiftPressed ? true : false;
            var isAltModifierValid   = _settings.UseAltKey == e.isAltPressed ? true : false;
            var isWindModifierVaild  = _settings.UseWindowsKey == e.isWinPressed ? true : false;

            // if all conditions are true and align with the settings show the Clipboard screen
            if (e.Key == userHotKey && isCtrlModifierValid && isShiftModifierValid && isAltModifierValid && isWindModifierVaild)
            {
                Log.Debug().Write("Conditions for show ClipBoard screen met.");
                showScreen();
            }

            //control-v pressed
            if (e.Key == Keys.V && e.isCtrlPressed)
            {
                Log.Verbose().Write("Paste value triggered by CTRL + V.");
                recordPaste();
            }
        }
Пример #9
0
        private void TestKeyHandler_SequenceWithOptionalKeys_OneTry()
        {
            var sequenceHandler = new KeySequenceHandler(
                new KeyCombinationHandler(VirtualKeyCode.Print),
                new KeyOrCombinationHandler(
                    new KeyCombinationHandler(VirtualKeyCode.Shift, VirtualKeyCode.KeyA),
                    new KeyCombinationHandler(VirtualKeyCode.Shift, VirtualKeyCode.KeyB))
                )
            {
                Timeout = null
            };

            bool result;

            // Print key
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Print));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Print));
            Assert.False(result);

            // Shift KeyB
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Shift));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.KeyB));
            Assert.True(result);
            // Shift KeyB
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.KeyB));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Shift));
            Assert.False(result);
        }
Пример #10
0
 private void OnKeyDown(KeyboardHookEventArgs args)
 {
     if (args.Key == Keys.Escape)
     {
         Close();
     }
 }
Пример #11
0
        private void TestKeyHandler_KeySequenceHandler_Right()
        {
            var sequenceHandler = new KeySequenceHandler(
                new KeyCombinationHandler(VirtualKeyCode.Print),
                new KeyCombinationHandler(VirtualKeyCode.Shift, VirtualKeyCode.KeyA))
            {
                Timeout = null
            };

            var result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Print));

            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Print));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Control));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Control));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Control));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Shift));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.KeyA));
            Assert.True(result);
        }
Пример #12
0
        private void TestKeyHandler_KeySequenceHandler_Wrong_Right()
        {
            var sequenceHandler = new KeySequenceHandler(
                new KeyCombinationHandler(VirtualKeyCode.Print),
                new KeyCombinationHandler(VirtualKeyCode.Shift, VirtualKeyCode.KeyA))
            {
                // Prevent debug issues, we are not testing the timeout here!
                Timeout = null
            };

            var result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Print));

            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Shift));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.KeyB));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.KeyB));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Shift));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Print));
            Assert.False(result);

            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.Shift));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyDown(VirtualKeyCode.KeyA));
            Assert.True(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.KeyA));
            Assert.False(result);
            result = sequenceHandler.Handle(KeyboardHookEventArgs.KeyUp(VirtualKeyCode.Shift));
            Assert.False(result);
            Assert.False(sequenceHandler.HasKeysPressed);
        }
        /// <include file='Internal.xml' path='Docs/KeyboardHook/HookCallback/*'/>
        protected override bool HookCallback(int code, UIntPtr wparam, IntPtr lparam)
        {
            if (KeyboardEvent == null)
            {
                return(false);
            }

            KeyboardEvents kEvent = (KeyboardEvents)wparam.ToUInt32();

            if (kEvent != KeyboardEvents.KeyDown &&
                kEvent != KeyboardEvents.KeyUp &&
                kEvent != KeyboardEvents.SystemKeyDown &&
                kEvent != KeyboardEvents.SystemKeyUp)
            {
                return(false);
            }

            KeyboardHookEventArgs kea = GetKeyboardReading(lparam);

            if (kea == null)
            {
                return(false);
            }

            KeyboardEvent(kEvent, kea);

            return(kea.Cancel);
        }
Пример #14
0
 private void ShortCutHandler(KeyboardHookEventArgs e)
 {
     if (e.Key == Keys.F1 && e.isAltPressed)
     {
         trayTrayIcon_DoubleClick(null, null);
     }
 }
Пример #15
0
        // Hook Event
        private void Hooker_HotkeyDown(object sender, KeyboardHookEventArgs e)
        {
            debugLog("[Event] Event " + e.Name + " launched");

            // STOP and VOLUME Hotkeys
            if (e.Name == "HK_STOP")
            {
                stopSound();
                return;
            }
            else if (e.Name == "HK_VOLUP")
            {
                changeVolume(true);
                return;
            }
            else if (e.Name == "HK_VOLDOWN")
            {
                changeVolume(false);
                return;
            }

            // Is Hook actually a song Name
            foreach (HKSound sound in soundFiles)
            {
                if (sound.name == e.Name)
                {
                    playSoundAtPos(soundFiles.IndexOf(sound));
                }
            }
        }
Пример #16
0
 protected virtual void OnKeyUpIntercepted(KeyboardHookEventArgs e)
 {
     if (KeyUpIntercepted != null)
     {
         KeyUpIntercepted.Invoke(e);
     }
 }
Пример #17
0
 /// <summary>
 /// Raises the KeyIntercepted event.
 /// </summary>
 /// <param name="e">An instance of KeyboardHookEventArgs</param>
 public void OnKeyIntercepted(KeyboardHookEventArgs e)
 {
     if (KeyIntercepted != null)
     {
         KeyIntercepted(e);
     }
 }
        private void MouseAndKeyboardHookService_KeyboardAction(object sender, KeyboardHookEventArgs e)
        {
            if (e.State == KeyState.Pressed)
            {
                if (e.Key == Key.Return || e.Key == Key.Space && AcceptHotKeysCommand.CanExecute(null))
                {
                    AcceptHotKeysCommand.Execute(null);
                }
            }
            if (e.State == KeyState.Released)
            {
                if (e.Key == Key.Escape)
                {
                    ChangeHotKeyPopupClosedCommand.Execute(null);
                    return;
                }
                else if (e.Key == Key.Return || e.Key == Key.Space || e.Key == Key.Tab)
                {
                    return;
                }

                _keyboardShortcut.Add(e.Key);
                DisplayedTemporaryKeyboardShortcut = KeyToString(_keyboardShortcut);
                AcceptHotKeysCommand.RaiseCanExecuteChanged();
            }

            e.Handled = true;
        }
Пример #19
0
        private void TestKeyHandler_KeyCombinationHandler_Repeat()
        {
            var keyCombinationHandler = new KeyCombinationHandler(VirtualKeyCode.Print);

            var keyPrintDown = new KeyboardHookEventArgs
            {
                Key       = VirtualKeyCode.Print,
                IsKeyDown = true
            };

            var keyPrintUp = new KeyboardHookEventArgs
            {
                Key       = VirtualKeyCode.Print,
                IsKeyDown = false
            };

            var result = keyCombinationHandler.Handle(keyPrintDown);

            Assert.True(result);
            result = keyCombinationHandler.Handle(keyPrintDown);
            Assert.False(result);

            // Key up again
            result = keyCombinationHandler.Handle(keyPrintUp);
            Assert.False(result);
            result = keyCombinationHandler.Handle(keyPrintDown);
            Assert.True(result);
        }
        public static List <string> GetKeyboardHookEventArgsAsList(KeyboardHookEventArgs keyboardHookEventArgs, string keyStart = "[", string keyEnd = "]")
        {
            List <string> keys = new List <string>();

            // modifier keys
            if (keyboardHookEventArgs.isShiftPressed)
            {
                keys.Add(keyStart + "Shift" + keyEnd);
            }

            if (keyboardHookEventArgs.isCtrlPressed)
            {
                keys.Add(keyStart + "Ctrl" + keyEnd);
            }

            if (keyboardHookEventArgs.isAltPressed)
            {
                keys.Add(keyStart + "Alt" + keyEnd);
            }

            if (keyboardHookEventArgs.isWinPressed)
            {
                keys.Add(keyStart + "Win" + keyEnd);
            }

            // actual hotkey
            if (keyboardHookEventArgs.Key != Keys.None)
            {
                keys.Add(keyStart + keyboardHookEventArgs.Key.ToString() + keyEnd);
            }

            return(keys);
        }
Пример #21
0
 private void Fire_KeyDown(KeyboardHookEventArgs kea)
 {
     if (KeyDown != null)
     {
         KeyDown(this, kea);
     }
 }
        private bool CompareKeyArgs(KeyboardHookEventArgs kea1, KeyboardHookEventArgs kea2)
        {
            if (kea1.Key != kea2.Key)
            {
                return(false);
            }
            if (kea1.Alt != kea2.Alt)
            {
                return(false);
            }
            if (kea1.Ctrl != kea2.Ctrl)
            {
                return(false);
            }
            if (kea1.Shift != kea2.Shift)
            {
                return(false);
            }
            if (kea1.CapsLock != kea2.CapsLock)
            {
                return(false);
            }
            if (kea1.Cancel != kea2.Cancel)
            {
                return(false);
            }

            return(true);
        }
        private KeyboardHookEventArgs[] GenerateRandomKeyData()
        {
            System.Windows.Forms.Keys[] keys = new System.Windows.Forms.Keys[]
            {
                System.Windows.Forms.Keys.Escape,
                System.Windows.Forms.Keys.N,
                System.Windows.Forms.Keys.F10,
                System.Windows.Forms.Keys.C,
                System.Windows.Forms.Keys.Enter,
                System.Windows.Forms.Keys.R,
                System.Windows.Forms.Keys.NumPad2,
                System.Windows.Forms.Keys.Z
            };

            Random rand = new Random(0);
            KeyboardHookEventArgs keyArgs;
            ArrayList             keysList = new ArrayList();

            for (int i = 0; i < 1000; i++)
            {
                System.Windows.Forms.Keys key = keys[rand.Next() % keys.Length];
                bool alt      = rand.Next() % 2 == 1;
                bool ctrl     = rand.Next() % 2 == 1;
                bool shift    = rand.Next() % 2 == 1;
                bool capsLock = rand.Next() % 2 == 1;

                keyArgs = new KeyboardHookEventArgs(key, alt, ctrl, shift, capsLock);
                keysList.Add(keyArgs);
            }

            return((KeyboardHookEventArgs[])keysList.ToArray(typeof(KeyboardHookEventArgs)));
        }
Пример #24
0
 private void keyHook_OnKeyDown(object sender, KeyboardHookEventArgs e)
 {
     // If we're the active table, discard any keys sent to this table specifically, Core'll take care of things
     if (Settings.UseKeyboardControls && Core.ActiveTable == this)
     {
         e.discard = true;
     }
 }
Пример #25
0
 /// <summary>
 /// Fires when a key is received
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void kh_OnKeyDown(object sender, KeyboardHookEventArgs e)
 {
     // Discard the key if we're the active table
     if (Settings.UseKeyboardControls && IsActiveTable && blockingKeys.Contains(e.keycode))
     {
         e.discard = true;
     }
 }
Пример #26
0
 private static void KeyDown(KeyboardHookEventArgs e)
 {
     if (e.Key != Settings.ImmediateResizeKey || (_rez != null && !_rez.IsDisposed))
     {
         return;
     }
     _rez = new ImmResize();
     _rez.Show();
 }
Пример #27
0
        protected virtual void OnKeyboardEvent(KeyboardEvents kEvent, KeyboardHookEventArgs kea)
        {
            if (KeyboardEvent == null)
            {
                return;
            }

            KeyboardEvent(kEvent, kea);
        }
Пример #28
0
        private void KeyboardHookOnKeyDown(object sender, KeyboardHookEventArgs e)
        {
            if (!Visible || Form.ActiveForm != FindForm())
            {
                return;
            }
            if (!followRT)
            {
                var colCount  = rtGrid.ColumnCount;
                var rowCount  = rtGrid.RowCount;
                var cellCount = colCount * rowCount;

                var tableIndex = rtGrid.CurrentCellAddress.Y * colCount + rtGrid.CurrentCellAddress.X;
                switch (e.Key)
                {
                case Keys.D:
                    tableIndex = (tableIndex + 1) % cellCount;
                    SetCurrentCell(tableIndex);
                    break;

                case Keys.A:
                    tableIndex = (tableIndex - 1 + cellCount) % cellCount;
                    SetCurrentCell(tableIndex);
                    break;

                case Keys.W:
                    tableIndex = (tableIndex - colCount + cellCount) % cellCount;
                    SetCurrentCell(tableIndex);
                    break;

                case Keys.S:
                    tableIndex = (tableIndex + colCount) % cellCount;
                    SetCurrentCell(tableIndex);
                    break;
                }
            }

            if (!onlineManager.FirmwareManager.IsOpened)
            {
                return;
            }
            switch (e.Key)
            {
            //case (Keys)(189):
            //case Keys.Subtract:
            case Keys.K:
                ChangeTableValue((ModifierKeys & Keys.Shift) == Keys.Shift ? -10 : -1);
                break;

            //case (Keys)(187):
            //case Keys.Add:
            case Keys.L:
                ChangeTableValue((ModifierKeys & Keys.Shift) == Keys.Shift ? 10 : 1);
                break;
            }
        }
        //
        // Test methods
        //
        public bool TriggerKeyAction(KeyboardEvents keyEvent, KeyboardHookEventArgs kea)
        {
            if (!installed)
            {
                string msg = "Key trigger cannot be used when the hook is uninstalled.";
                throw new InvalidOperationException(msg);
            }

            return(OnKeyboardEvent(keyEvent, kea.Key, kea.Alt, kea.Ctrl, kea.Shift, kea.CapsLock));
        }
Пример #30
0
        private void Global_KeyUp(KeyboardHookEventArgs e)
        {
            if (!IsStarted || (int)e.Key != 32)
            {
                return;
            }

            IsStarted = false;
            MessageBox.Show("Stopped");
        }
Пример #31
0
    /// <summary>
    /// This function is an event handler for the KeyIntercepted.
    /// It intercepts ALL keys from the keyboard input from the buffer.
    /// </summary>
    /// <param name="keyboardEvents">Contains the Key Enum, and the Key Code</param>
    void KeyboardHookInstance_KeyIntercepted(KeyboardHookEventArgs keyboardEvents)
    {
        if (keyboardEvents.PressedKey == Keys.PrintScreen)
        {
            takeSnapShot();
        }

        if (keyboardEvents.PressedKey == Keys.F8)
        {
            this.Visible = !this.Visible;
        }
    }
Пример #32
0
 private void keyHook_OnKeyDown(object sender, KeyboardHookEventArgs e)
 {
     // If we're the active table, discard any keys sent to this table specifically, Core'll take care of things
     if (Settings.UseKeyboardControls && Core.ActiveTable == this)
         e.discard = true;
 }
Пример #33
0
 /// <summary>
 /// Raises the KeyIntercepted event.
 /// </summary>
 /// <param name="e">An instance of KeyboardHookEventArgs</param>
 public void OnKeyIntercepted(KeyboardHookEventArgs e)
 {
     if (KeyIntercepted != null)
         KeyIntercepted(e);
 }
 /// <summary>
 /// Used to show a balloon when typing. Hooked into KeyboardHook.
 /// </summary>
 private static void KeyboardEventBalloon(object sender, KeyboardHookEventArgs args)
 {
     if (!Pause)
     {
         char c = (char)args.AsciiCode;
         char d = args.FlagUp ? '↑' : '↓';
         ShowBalloon("You Typed", "" + c + d, 0.5f);
     }
 }
        /// <summary>
        /// Sends the keyboard events into the collector
        /// </summary>
        private static void KeyboardEventCollect(object sender, KeyboardHookEventArgs args)
        {
            if(Highlander.WaitOne())
            {

                if (!Pause && activeSession)
                {
                    double score = IDverify.KeyEvent(args);
                    if (!openTrust && Verifiers.trainingUser && !alreadyLocked)
                    {
                        alreadyLocked = true;
                        Lock("EndOpenTrust", "");
                        HF.openTrustWindow();
                        alreadyLocked = false;
                    }
                    if (score < 50)
                    {
                        if (!openTrust)
                        {
                            alreadyLocked = true;
                            Lock("Failed", "");
                            HF.openTrustWindow();
                            IdentityVerifier.TrustValue = 70;
                            failCount = 0;
                            alreadyLocked = false;
                        }
                        else
                        {
                            if (score != failscore || score == 0)
                            {
                                failCount++;
                                failscore = score;
                                if (failCount == 100)
                                {
                                    failCount = 0;
                                    if (File.Exists(Configuration.profilePath + @"\" + Verifiers.currentUser + Verifiers.keyboardNameCaptured /*+ Verifiers.contextChange*/ + @".xml"))
                                    {
                                        unlockFiles();
                                        File.Delete(Configuration.profilePath + @"\" + Verifiers.currentUser + Verifiers.keyboardNameCaptured /*+ Verifiers.contextChange*/ + @".xml");
                                        lockFiles();
                                        Verifiers.keyboardChange = true; // Note the keyboard has not actually changed we are just using this to force the system into trainin mode --N
                                    }
                                }
                            }
                        }
                        ni.Icon = ActiveAuthenticationDesktopClient.Properties.Resources.ARed;
                    }
                    else if (score < 70)
                    {
                        failCount = 0;
                        ni.Icon = ActiveAuthenticationDesktopClient.Properties.Resources.AYellow;
                    }
                    else
                    {
                        failCount = 0;
                        ni.Icon = ActiveAuthenticationDesktopClient.Properties.Resources.AGreen;
                    }
                    Highlander.ReleaseMutex();
                }
            }
            // Raises a flag if the keyboard in use changes --N
            if (Verifiers.keyboardNameCaptured != Verifiers.keyboardNameOnRecord)
            {
                Verifiers.keyboardNameOnRecord = Verifiers.keyboardNameCaptured;
                Verifiers.keyboardChange = true;
                IDverify.changeKeyboard(Verifiers.keyboardNameCaptured);
            }
        }
Пример #36
0
 /// <summary>
 /// Fires when a key is received
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void kh_OnKeyDown(object sender, KeyboardHookEventArgs e)
 {
     // Discard the key if we're the active table
     if (Settings.UseKeyboardControls && IsActiveTable && blockingKeys.Contains(e.keycode))
         e.discard = true;
 }
Пример #37
0
 private IntPtr HookCallback(
     int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
     {
         int vkCode = Marshal.ReadInt32(lParam);
         //Console.WriteLine((Keys)vkCode);
         KeyboardHookEventArgs keyHook = new KeyboardHookEventArgs(vkCode);
         KeyIntercepted(keyHook);
     }
     return CallNextHookEx(_hookID, nCode, wParam, lParam);
 }
        /// <summary>
        /// This method collects keystrokes and does magic to verify your identity!
        /// </summary>
        /// <param name="args">This is the KeyboardHookEventArgs that contains all info about the KSE</param>
        public double KeyEvent(KeyboardHookEventArgs args)
        {
            //Store the keyboardevents in the keyboard event table
            KeyboardEvents.Rows.Add(args.SID, "", args.KeyEvent, args.VkCode, (args.KeyEventTime-621355968000000000) / 10000);
            #if Recording
            KElog.Rows.Add(args.SID, "", args.KeyEvent, args.VkCode, (args.KeyEventTime - 621355968000000000) / 10000);
            #endif

            //Check if a full sample has been collected and if so ship it to the feature extractors
            if (KeyboardEvents.Rows.Count > 0 && KeyboardEvents.Rows.Count % Configuration.slidingWindowJump == 0)//if enough events have been collected for a microsample
            {
                #if Recording
                KELOG.WriteXml(Path.GetPathRoot(Environment.SystemDirectory)+@"Users\Azriel\Desktop\NEWKahona");
            #endif
                //Get and assign the sampleID to each row
                string sampleId = Guid.NewGuid().ToString();
                foreach (DataRow row in KeyboardEvents.Rows)
                    row["SampleId"] = sampleId;

                #region FeatureExtractors
                //Create a dataset to store the feature extractor data
                DataSet extracted = new DataSet();
                extracted.Clear();
                foreach (FeatureExtractor fe in extractors)
                {
                    //Run Feature Extractors
                    extracted.Tables.Add(fe.extract(KeyboardEvents));
                }
                //Create a table to hold the total feature extractor data
                DataTable features = new DataTable();
                foreach (DataTable dt in extracted.Tables)
                {
                    //Combine feature extractor tables
                    features.Merge(dt);
                }

                microSamplesSent++;

                // Increment the sample counter to output how many samples have been sent when this user completes.
                if (microSamplesSent >= Configuration.numSkippedSamples)
                {
                    sampleCount++;
                    microSamplesSent = 0;
                }

                if (KeyboardEvents.Rows.Count >= Configuration.keyEventsPerSample)
                {
                    //Slide the window down
                    for (int i = 0; i < Configuration.slidingWindowJump; i++)
                    {
                        KeyboardEvents.Rows.RemoveAt(0);
                    }
                }
                DataSet dsfeatures = new DataSet();
                dsfeatures.Tables.Add(features);
                #endregion
                //Send the feature extractor scores into the verifiers
                DataSet verifierScores = verifiers.RunVerifier(dsfeatures);

                if (verifierScores.Tables[0].Rows.Count>0)
                {
                    #if OutputScores
                    //verifierScores.WriteXml(Path.GetPathRoot(Environment.SystemDirectory)+@"Users\Azriel\Desktop\Scores\VerifierScores\" + sampleCount.ToString() + microSamplesSent.ToString() + "scores.xml"); this appears to be here for verification purposes --N
                    #endif
                    //Send the verifier scores into the fuser
                    DataTable Scores = Fuse_MajorityVoting(verifierScores);
                    updateTrust((double)Scores.Rows[0]["Score"], (double)Scores.Rows[0]["Threshold"]);
                    #if DEBUG
                    Console.WriteLine("Score = " + ((double)Scores.Rows[0]["Score"]).ToString());
                    Console.WriteLine("Trust = " + TrustValue.ToString());
                    #endif
                    return TrustValue;
                }
            }
            return TrustValue;
        }