#!/usr/bin/env python

import pylirc, time
from pykeyboard import PyKeyboard
from pymouse import PyMouse

k = PyKeyboard()
m = PyMouse()

blocking = 0;

x = 0
y = 0

def setup():
	pylirc.init("irexec") #pylirc.init("pylirc", "./conf", blocking)

def key_press(config):
	if config == 'pause':
		k.tap_key(k.function_keys[5]) 
		print 'Pause'
		
	if config == 'setup':
                k.press_key(k.shift_key)
		k.tap_key(k.function_keys[5])
		k.release_key(k.shift_key)
		print 'Setup'

	if config == 'left':
                global x
                x -= 50
                global y
                m.move(x,y)                      
		print 'left'

	if config == 'right':
		x += 50               
                m.move(x,y)
                print 'right'

        if config == 'up':
                y -= 20
                m.move(x,y)                      
		print 'up'

	if config == 'down':
		y += 20               
                m.move(x,y)
                print 'down'
                
	if config == 'zero':
                k.press_key(k.control_key)
	        k.tap_key('b')
	        k.release_key(k.control_key)
		print 'blank screen'
		
	if config == 'one':
                k.tap_key(k.escape_key)
		print 'one'
		
	if config == 'two':
                k.tap_key(k.up_key)
		print 'up arrow'
		
	if config == 'three':
                
		print 'Green'
		
	if config == 'four':
                k.tap_key(k.left_key)
		print 'left arrow'
		
	if config == 'five':
                x_dim, y_dim = m.position()
                m.click(x_dim, y_dim, 1)
		print 'Green'
		
	if config == 'six':
                k.tap_key(k.right_key)
		print 'right arrow'
		
	if config == 'seven':
                m.scroll(-3, 0)
		print 'Green'
		
	if config == 'eight':
                k.tap_key(k.down_key)
		print 'down arrow'
		
	if config == 'nine':
                m.scroll(+3, 0)
		print 'Green'

	if config == 'volumeup':
                x += 10               
                m.move(x,y)
		print 'Blue OFF'

	if config == 'volumedown':
                x -= 10               
                m.move(x,y)
		print 'Light Blue'

def loop():
	while True:
		s = pylirc.nextcode(1)
		
		while(s):
			for (code) in s:
				print 'Command: ', code["config"] #For debug: Uncomment this
#				line to see the return value of buttons
				key_press(code["config"])
			if(not blocking):
				s = pylirc.nextcode(1)
			else:
				s = []

def destroy():
	pylirc.exit()

if __name__ == '__main__':
	try:
		setup()
		loop()
	except KeyboardInterrupt:
		destroy()
