Sign in to follow this  
Followers 0
Guest Zeliard2000

PixelGetColor not working in game

4 posts in this topic

Hi guys,

I've been trying to write a simple program that reads in the color of a certain pixel in game. Then if the pixel color matches, it performs a right-click. But the problem i'm having is that when using PixelGetColor, instead of reading a pixel from the game, it reads in a pixel from my Desktop background. Can someone help me with this, thanks.

Here's my code:

Global $Paused
HotKeySet("{CAPSLOCK}", "TogglePause")
Dim $v1
Dim $v2 = 11730944
While 1
    sleep(100)
    $v1 = PixelGetColor(3611, 847)
    If $v1 == $v2 Then
        MouseClick("right")
    EndIf
WEnd

Func TogglePause()
    $Paused = NOT $Paused
  While $Paused
      sleep(100)
  WEnd
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I wish my monitor was 3611 pixels wide... Either typo or you have 3-4 monitors in wish case you'll have to do some experimenting depending if the game is full screen and at what resolution etc.

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try this if it's reading your desktop

Opt("PixelCoordMode", 0); set get color to active window
Opt("MouseCoordMode", 0); set mouseclick to active window

WinActivate("Your Game Title Here")
Global $Paused
HotKeySet("{CAPSLOCK}", "TogglePause")
Dim $v1
Dim $v2 = 11730944

While WinExist("Your Game Title Here")
    sleep(100)
    $v1 = PixelGetColor(3611, 847)
    If $v1 == $v2 Then
        MouseClick("right")
    EndIf
WEnd

Func TogglePause()
    $Paused = NOT $Paused
  While $Paused
      sleep(100)
  WEnd
EndFunc

Hope this helps.

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Try this if it's reading your desktop

Opt("PixelCoordMode", 0); set get color to active window
Opt("MouseCoordMode", 0); set mouseclick to active window

WinActivate("Your Game Title Here")
Global $Paused
HotKeySet("{CAPSLOCK}", "TogglePause")
Dim $v1
Dim $v2 = 11730944

While WinExist("Your Game Title Here")
    sleep(100)
    $v1 = PixelGetColor(3611, 847)
    If $v1 == $v2 Then
        MouseClick("right")
    EndIf
WEnd

Func TogglePause()
    $Paused = NOT $Paused
  While $Paused
      sleep(100)
  WEnd
EndFunc

Hope this helps.

<{POST_SNAPBACK}>

Hmm, i'll try it out, thanks for the help.

P.S. Yikes, now that I think about it, there's no way my monitor could have a 3611 resolution size in it. Adobe photoshop must be using some other kind of unit, thanks for pointing that out :) .

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