Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: API to move mouse, grab pixels on screen?

  1. #1
    Join Date
    Jan 2006
    Location
    Ontario, Canada
    Beans
    708

    API to move mouse, grab pixels on screen?

    Hey all, is there a Linux API (preferably C++) to:
    * Move the mouse to any coordinate on the screen.
    * Get the position of the mouse on the screen.
    * Get the colour value of a pixel on the screen at any given coordinate
    ?

  2. #2
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: API to move mouse, grab pixels on screen?

    SDL maybe? I'm not 100% sure about setting the mouse co-ords but it does input so i imagine it should be able to do that.

  3. #3
    Join Date
    Jan 2006
    Location
    Ontario, Canada
    Beans
    708

    Re: API to move mouse, grab pixels on screen?

    Quote Originally Posted by mike_g View Post
    SDL maybe? I'm not 100% sure about setting the mouse co-ords but it does input so i imagine it should be able to do that.
    So SDL can work directly with X? Let's say I want to make a simple command line C++ program to get the current coordinates of the mouse and RGB values for that coordinate when run. Can SDL do that?

  4. #4
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: API to move mouse, grab pixels on screen?

    Nah I don't think so. It will just set up a screen with double buffering to draw to, then you can get pixel values within it. Sorry, dident know that was what you were after.

  5. #5
    Join Date
    Jan 2006
    Location
    Ontario, Canada
    Beans
    708

    Re: API to move mouse, grab pixels on screen?

    Quote Originally Posted by mike_g View Post
    Nah I don't think so. It will just set up a screen with double buffering to draw to, then you can get pixel values within it. Sorry, dident know that was what you were after.
    It's ok, thanks for the reply anyway!

  6. #6
    Join Date
    Jan 2006
    Location
    Philadelphia
    Beans
    4,076
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: API to move mouse, grab pixels on screen?

    well, for python, there's python-xlib (http://python-xlib.sourceforge.net/)

    there's just plain xlib for c (http://tronche.com/gui/x/xlib/)

    both will be capable of doing what you say you want to do.

  7. #7
    Join Date
    May 2008
    Beans
    3

    Re: API to move mouse, grab pixels on screen?

    Here, try this code. It uses python-xlib and does exactly what you want ! (taken from python-linux implementation of wiiwhiteboard: sourceforge.net/project/wiiwhiteboard)

    import Xlib.display
    import Xlib.ext.xtest

    class MouseControl:
    def __init__(self):
    self.display = Xlib.display.Display()
    self.screen = self.display.screen()
    self.root = self.screen.root

    def mouse_click(self, button):
    self.mouse_down(button)
    self.mouse_up(button)

    def mouse_down(self, button): #button= 1 left, 2 middle, 3 right
    Xlib.ext.xtest.fake_input(self.display,Xlib.X.Butt onPress, button)
    self.display.sync()

    def mouse_up(self, button):
    Xlib.ext.xtest.fake_input(self.display,Xlib.X.Butt onRelease, button)
    self.display.sync()

    def mouse_warp(self, x,y):
    self.root.warp_pointer(x,y)
    self.display.sync()

    def get_screen_resolution(self):
    return self.screen['width_in_pixels'], self.screen['height_in_pixels']

  8. #8
    Join Date
    Oct 2006
    Location
    Austin, Texas
    Beans
    2,715

    Re: API to move mouse, grab pixels on screen?

    Quote Originally Posted by fuelnatchos View Post
    ...
    Posting Python code...


  9. #9
    Join Date
    Feb 2007
    Location
    Portland, OR
    Beans
    127
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: API to move mouse, grab pixels on screen?

    hey wybiral, nice to see you again. want to show me the right way?
    -------------
    eh.

  10. #10
    Join Date
    Feb 2008
    Location
    /home/
    Beans
    379
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: API to move mouse, grab pixels on screen?

    If you're good with java, then the Robot class is perfect for you.

    Java Doc:
    java.awt.Robot

    I have used it to do just what you want.
    Code:
    public class Robo {
    	
    public static void main(String[] args) throws AWTException {
    Robot robot = new Robot(); robot.mouseMove(100, 100); robot.getPixelColor(100, 100);
    }
    }
    If there's one thing worse than a program that doesn't work when it should, it's a program that does work when it shouldn't.

    Bob Archer

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •