Jump to content

Help Scanning for Keyboard input


Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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.

Link to comment
Share on other sites

....

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
Link to comment
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

Link to comment
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
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!

Link to comment
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.

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...