Sign in to follow this  
Followers 0
Kevinsyel

Help Scanning for Keyboard input

10 posts in this topic

Hi, I'm new to this board, and am trying to learn how to use AutoIT.

I have a deliverable to produce, and I'm a bit stuck.

My script needs to be able to cause the mouse to click-drag from one end of the screen to another repeatedly until interrupted, while I collect Data on the FPS the current application is running with.

The click-drag is to run a simulated test of scroll functions to test a scrolling gui.

I'm essentially using a MouseClickDrag("Left", #, #, #, #, 200) to scroll.

however, I want it to loop, so I was planning on using a Do... Until... loop...

however, I can't seem to find information on how to scan for keyboard input so when the user presses "esc" the bot ends.

essentially I have:

Do

MouseClickDrag("left", 1700, 50, 0, 70, 200)

if ;This is where I want to do the input

Until ;the keyboard check comes back true.

is there a function in this scripting language that scans the keyboard and I can check to verify when and only when a key has been pressed?

After that, I may have questions about gathering information from the application running to check FPS.

Thanks

Share this post


Link to post
Share on other sites



You kinda manage to touch two "very sensitive" subjects in the very first post "bots" and "keyloggers" :mellow:

I really doubt you'll get help here.

Something to read first:

Game Bots

About keyloggers


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

hmmmm, without touching on keyloggers in general, HotKeySet is a function in AutoIT that can can detect a specific keypress event. The example in the helpfile actually uses the esc key. Look it up.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Yeah, I was actually hopingI wouldn't offend people.

Essentially this would be a bot, because this would allow my company to run automated tests on our machines overnight so that we can check for data management and frame drops on release candidates. The only thing is, the company doesnt want to spare the engineers to do this, and I (a tester) have been asked to program this. My strong point is C++ and I'm essentially just looking for the syntax.

I found the "_IsPressed call which helped quite a bit... but now it turns out that the software I want to test doesnt scroll in a loop, so I have to scroll back and forth to test for frame drops.

I am hitting an error though, a mismatched Until with Do...

I'm sure nothing is amiss, but I am not familiar with this syntax

My code looks like this:

#Include <Misc.au3>

$sideBit = 0

$exVar = false

Do

if $sideBit = 0 then

MouseClickDrag("left", 1700, 50, 0, 70, 200)

$sideBit = 1

else

MouseClickDrag("left", 0, 70, 1700, 50, 200)

$sideBit = 0

if _IsPressed(0x09) then $exVar = true

Until $exVar = True

my exitVariable (exVar) determines to exit the loop while the side bit determines if I scroll from the left or the right.

Can anybody see an error I may have over looked?

hopefully me clarifying my purposes helps

Thanks

*edit: Thank you Enaiman for the posts on the Bots and Keylogging. I read them thoroughly to be sure I'm not violating any ToS. And since the software I'm designing this for is a prototype and doesn't even have a EULA yet... I'm sure I'm not violating that, lol.

Anyways, I wanted to be sure I am within the code of conduct on this board. I hate as trolls as much as everyone else, and I hope to contribute back when I become more proficient.

Edited by Kevinsyel

Share this post


Link to post
Share on other sites

HotKeySet is definatley what you are looking for then.

Declare a global variable $exitloop set it false before your loop and loop until it is true.

Register a hotkey for esc, and in the function set the variable to true.

Lookup HotKeySet for more infomration andor an example.

Share this post


Link to post
Share on other sites

No problem at all - any honest user is more than welcome here :mellow:


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

....

My code looks like this:

#Include <Misc.au3>

$sideBit = 0

$exVar = false

Do

if $sideBit = 0 then

MouseClickDrag("left", 1700, 50, 0, 70, 200)

$sideBit = 1

else

MouseClickDrag("left", 0, 70, 1700, 50, 200)

$sideBit = 0

if _IsPressed(0x09) then $exVar = true

Until $exVar = True

....

If - Else is missing an EndIf.

_IsPressed(0x09) should be _IsPressed('09') for Tab button.

If you look at _IsPressed() function in the Misc.au3 UDF file in the include directory, the DllCall within, uses '0x' & $sHexKey as the parameter to identify the key pushed. So using _IsPressed(0x09) would result in the DllCall parameter being 0x0x09 which will cause an error which would be handled by the following line in _IsPressed() function.

#include <Misc.au3>

Local $sideBit = 0

Do
    If $sideBit = 0 Then
        MouseClickDrag("left", 1700, 50, 0, 70, 200)
        $sideBit = 1
    Else
        MouseClickDrag("left", 0, 70, 1700, 50, 200)
        $sideBit = 0
    EndIf
Until _IsPressed('1B') ; Esc to exit loop

Edit: 0x09 would convert to 9 decimal. So, the DllCall parameter would be 0x9 which would be acceptable for Tab.

Edited by Malkey

Share this post


Link to post
Share on other sites

I thought about the fact that the syntax might have an "Endif" statement on my way home from work, and when I tried the Endif, it worked.

I'm so used to C++ where you just go

if(side == 0)

{

//move mouse code

side = 1;

}

else

{

//move mouse code

side = 0;

}

now all I need to do is find out some what to scan the program running for the current FPS being displayed.

thinking about maybe using ProcessGetStats to see if I can get some data from that?

Or should I just say "I gave you mouse control, here is something called 'FRAPS'?" lol

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

if your program does not have a built in display for FPS

you could do a pixelgetcolor on a specific spot that hopefully is not the same from 1 frame to the next. Then have a counter that increases by 1 each time that pixel changes then display a result every second of the current count then reset the count.

something like:

Global $color2
$count = 0

GUICreate("FPS",120,40)
GUICtrlCreateLabel("FPS=", 1, 10)
GUISetState(@SW_SHOW)

$label = GUICtrlCreateLabel($count, 27, 10)
$timer = TimerInit()

While 1

    $color = PixelGetColor(x, y);enter the pixelcoordinates to check

    If $color <> $color2 Then
        $count += 1
        $color2 = $color
    EndIf

    $dif = TimerDiff($timer)

    If $dif > 1000 Then
        GUICtrlSetData($label, $count)
        $count = 0
        $timer = TimerInit()
    EndIf

WEnd
Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

if your program does not have a built in display for FPS

you could do a pixelgetcolor on a specific spot that hopefully is not the same from 1 frame to the next. Then have a counter that increases by 1 each time that pixel changes then display a result every second of the current count then reset the count.

something like:

Global $color2
$count = 0

GUICreate("FPS",120,40)
GUICtrlCreateLabel("FPS=", 1, 10)
GUISetState(@SW_SHOW)

$label = GUICtrlCreateLabel($count, 27, 10)
$timer = TimerInit()

While 1

    $color = PixelGetColor(x, y);enter the pixelcoordinates to check

    If $color <> $color2 Then
        $count += 1
        $color2 = $color
    EndIf

    $dif = TimerDiff($timer)

    If $dif > 1000 Then
        GUICtrlSetData($label, $count)
        $count = 0
        $timer = TimerInit()
    EndIf

WEnd

Awesome. Thanks for the idea.

I dont think I can run this within the same code though, because while mouse movement is being processed, this code won't be running, so I will have a seperate FPS app to run in the background. I think I'll have it output the FPS to a text dump as well so that it can be scanned through. I saw some functions for that, and I've done text loading a lot. should be easy.

Thanks again.

Share this post


Link to post
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
Sign in to follow this  
Followers 0