Grab the color of the pixel on screen

#!/usr/bin/env python import pygtk import gtk def getRGBAtPointer(): """Returns an (R, G, B) tuple at the current pointer location.""" root_window = gtk.gdk.get_default_root_window() pointer_x, pointer_y = gtk.gdk.Display(None).get_pointer()[1:3] print pointer_x, pointer_y pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1) pixbuf = pixbuf.get_from_drawable(root_window, root_window.get_colormap(), pointer_x, pointer_y, 0, 0, 1, 1) return tuple(map(ord, pixbuf.get_pixels()[:3])) print getRGBAtPointer() 

 

Spiral searching algorithm:

 

# spiral searching centerx = 400 centery = 300 def findcolor2(): loopn=0 for loop in range(1, 100): for loopx in range(-loop, loop+1): print centerx+loopx, centery-loop cmd = "xdotool mousemove " + str(centerx+loopx) + " " + str(centery-loop) os.system(cmd) time.sleep(0.05) for loopy in range(-loop+1, loop): print centerx-loop, centery+loopy cmd = "xdotool mousemove " + str(centerx-loop) + " " + str(centery+loopy) os.system(cmd) time.sleep(0.05) print centerx+loop, centery+loopy cmd = "xdotool mousemove " + str(centerx+loop) + " " + str(centery+loopy) os.system(cmd) time.sleep(0.05) for loopx in range(-loop, loop+1): print centerx+loopx, centery+loop cmd = "xdotool mousemove " + str(centerx+loopx) + " " + str(centery+loop) os.system(cmd) time.sleep(0.05) 

 

change wireless ip address on dos command:

 

netsh interface ip set address name="Wireless Network Connection" static 192.168.1.102 255.255.255.0 192.168.1.1 1

 

set wireless on dhcp:

 

netsh interface ip set address name="Wireless Network Connection" dhcp

 

set primary dns server address:

 

netsh int ip add dns "Wireless Network Connection" 172.20.168.3

 

set second dns server address:

 

netsh int ip add dns "Wireless Network Connection" 172.20.168.2 index=2

 

>>>

 

find mob sub function:

 

#!/usr/bin/env python import pygtk import os import gtk import time def get_color(pointer_x, pointer_y): """Returns an (R, G, B) tuple at the current pointer location.""" root_window = gtk.gdk.get_default_root_window() #pointer_x, pointer_y = gtk.gdk.Display(None).get_pointer()[1:3] #print pointer_x, pointer_y pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 1, 1) pixbuf = pixbuf.get_from_drawable(root_window, root_window.get_colormap(), pointer_x, pointer_y, 0, 0, 1, 1) return tuple(map(ord, pixbuf.get_pixels()[:3])) # spiral searching centerx = 566 centery = 419 color_rank = [(100, 220, 50), (150, 235, 70)]; def meet_color_range(color_rank, r, g, b): if (color_rank[0][0] <= r <= color_rank[1][0] and color_rank[0][1] <= g <= color_rank[1][1] and color_rank[0][2] <= b <= color_rank[1][2]): return 1 return 0 dist = 30 find_it = 0 def spiral_search(): loopn=0 global dist, find_it for loop in range(1, 100): if find_it == 1: break for loopx in range(-loop, loop+1): (r, g, b) = get_color(centerx+loopx, centery-loop) #print centerx+loopx, centery-loop, r, g, b if meet_color_range(color_rank, r, g, b) == 1: cmd = "xdotool mousemove " + str(centerx+loopx) + " " + str(centery-loop-dist) os.system(cmd) time.sleep(0.05) find_it = 1 print "find it: ", "(", centerx+loopx, ",", centery-loop, ") : (", r, ",", g, ",", b, ")" break for loopy in range(-loop+1, loop): (r, g, b) = get_color(centerx-loop, centery+loopy) #print centerx-loop, centery+loopy, r, g, b if meet_color_range(color_rank, r, g, b) == 1: cmd = "xdotool mousemove " + str(centerx-loop) + " " + str(centery+loopy-dist) os.system(cmd) time.sleep(0.05) find_it = 1 print "find it: ", "(", centerx-loop, ",", centery+loopy, ") : (", r, ",", g, ",", b, ")" break (r, g, b) = get_color(centerx+loop, centery+loopy) #print centerx+loop, centery+loopy, r, g, b if meet_color_range(color_rank, r, g, b) == 1: cmd = "xdotool mousemove " + str(centerx+loop) + " " + str(centery+loopy-dist) os.system(cmd) time.sleep(0.05) find_it = 1 print "find it: ", "(", centerx+loop, ",", centery+loopy, ") : (", r, ",", g, ",", b, ")" break for loopx in range(-loop, loop+1): (r, g, b) = get_color(centerx+loopx, centery+loop) #print centerx+loopx, centery+loop, r, g, b if meet_color_range(color_rank, r, g, b) == 1: cmd = "xdotool mousemove " + str(centerx+loopx) + " " + str(centery+loop-dist) os.system(cmd) time.sleep(0.05) find_it = 1 print "find it: ", "(", centerx+loopx, ",", centery+loop, ") : (", r, ",", g, ",", b, ")" break spiral_search()  

 

get a singal special key by using termios

 

def getkey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6][termios.VMIN] = 1 new[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSANOW, new) key = None try: key = os.read(fd, 4) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) return key # Use this list to find the key that we want. This is hard coded for xterm. def chkkey(key): keylist = { '/x1b':'escape', '/x7f':'backspace', '/x1bOH':'HOME', '/x1bOP':'F1', '/x1bOQ':'F2', '/x1bOR':'F3', '/x1bOS':'F4', '/x1b[15':'F5', '/x1b[17':'F6', '/x1b[18':'F7', '/x1b[19':'F8', '/x1b[20':'F9', '/x1b[21':'F10', '/x1b[23':'F11', '/x1b[24':'F12', '/x1b[A':'ARROW_UP', '/x1b[B':'ARROW_DN', '/x1b[C':'ARROW_RT', '/x1b[D':'ARROW_LT', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6', '7':'7', '8':'8', '9':'9', '0':'0' } if key in keylist: return keylist[key] else: return "Unknown"def getkey(): fd = sys.stdin.fileno() old = termios.tcgetattr(fd) new = termios.tcgetattr(fd) new[3] = new[3] & ~termios.ICANON & ~termios.ECHO new[6][termios.VMIN] = 1 new[6][termios.VTIME] = 0 termios.tcsetattr(fd, termios.TCSANOW, new) key = None try: key = os.read(fd, 4) finally: termios.tcsetattr(fd, termios.TCSAFLUSH, old) return key # Use this list to find the key that we want. This is hard coded for xterm. def chkkey(key): keylist = { '/x1b':'escape', '/x7f':'backspace', '/x1bOH':'HOME', '/x1bOP':'F1', '/x1bOQ':'F2', '/x1bOR':'F3', '/x1bOS':'F4', '/x1b[15':'F5', '/x1b[17':'F6', '/x1b[18':'F7', '/x1b[19':'F8', '/x1b[20':'F9', '/x1b[21':'F10', '/x1b[23':'F11', '/x1b[24':'F12', '/x1b[A':'ARROW_UP', '/x1b[B':'ARROW_DN', '/x1b[C':'ARROW_RT', '/x1b[D':'ARROW_LT', '1':'1', '2':'2', '3':'3', '4':'4', '5':'5', '6':'6', '7':'7', '8':'8', '9':'9', '0':'0' } if key in keylist: return keylist[key] else: return "Unknown"

 

preliminary robot schematic

 

#!/usr/bin/env python from multiprocessing import Process, Queue import curses, time def f(): while True: if process_terminal: print 'end process' break print 'processing', process_terminal if __name__ == '__main__': process_terminal = 0 print 'start....' scr = curses.initscr() curses.cbreak() curses.noecho() scr.keypad(1) try: while True: key = scr.getch() if key == curses.KEY_F8: # startup process_terminal = 0 p = Process(target=f, args=()) p.start() p.join() continue if key == curses.KEY_F9: p.terminate() # pause process_terminal = 1 continue if key == curses.KEY_F12: # end break pass finally: curses.nocbreak() scr.keypad(0) curses.echo() curses.endwin() 

 

 

你可能感兴趣的:(cmd,processing,import,NetWork,interface,Terminal)