Jump to content
Sign in to follow this  
azazul

Background window

Recommended Posts

azazul

Hi, All.

Sorry for noob question, but I'm new to AutoIT.

Here is my script. It's a basic buffing bot for RF Online. I want it to press keys when game window is NOT active, but script works only in active one.

Help me find the problem please.

AutoItSetOption("WinTitleMatchMode", 4)
$handle = WinGetHandle("RF Online - 1")

If WinExists($handle) Then
While 1
    $i = 0
    ControlSend($handle, "", "", "{F7}");press F7
    Sleep(500)
    While $i <= 121
        ControlSend($handle, "", "", "{F6}");press F6 every second for 2 minutes
        Sleep(1000)
        $i = $i + 1
    WEnd
    ControlSend($handle, "", "", "{F7}");press F7
    Sleep(500)
    ControlSend($handle, "", "", "{F8}");press F8
    Sleep(500)
    ControlSend($handle, "", "", "{F9}");press F9
    Sleep(500)
WEnd
EndIf

Share this post


Link to post
Share on other sites
dantay9

You could use winactivate() before the controlsend to activate the window.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
azazul

As I already mentioned,

I want it to press keys when game window is NOT active

I don't want to activate window. It works just fine when game window is active. The point is to make it work when game is in the backgrond.

Switching between active/background windowstates is also not an option. I want to surf, watch video, work, whatever, - while bot is working in background window.

Share this post


Link to post
Share on other sites
FreeFry

If it works fine when active, maybe the game window ignores key-presses when it's not active... In that case you're sorta stuck to keeping it active. :/

Edited by FreeFry

Share this post


Link to post
Share on other sites
azazul

Found kind of solution.

#Include <WinAPI.au3>

AutoItSetOption("WinTitleMatchMode", 4)
Global $handle = WinGetHandle("RF Online - 1")

If WinExists($handle) Then
While 1
    $i = 0
    Stroke("{F7}")
    Sleep(1000)
    While $i <= 120
        Stroke("{F6}")
        Sleep(1000)
        $i = $i + 1
    WEnd
    Stroke("{F7}")
    Sleep(1000)
    Stroke("{F8}")
    Sleep(1000)
    Stroke("{F9}")
    Sleep(1000)
WEnd
EndIf

Func Stroke($key)
    _SendMessage($handle, 0x6, 0x1)
    ControlSend($handle, "", "", $key)
    _SendMessage($handle, 0x6, 0x1)
EndFunc

It seems to work OK, when game window is NOT hidden, but in background (not active). The only problem is arrow keys: if I press them - my character lurks around, but I'm OK with that, 'cause I almost do not use them

Edited by azazul

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  

×