--- /dev/null
+# -*- coding: utf-8 -*-
+
+# ****************************************************************************
+# Copyright (c) 2008 INdT/Fucapi.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# ============================================================================
+# Project Name : PC Remote
+# Author : Nilson Silva, Jonatas Isvi, Andre Portela
+# Email : fergus.mao@gmail.com, jonatas.nona@gmail.com,
+# andre_portela_@hotmail.com
+# Reviewer : Jônatas Isvi
+# Email :
+# Version : 1.0
+# Package : services
+# Description : Mouse Server, Keyboard Server
+# ============================================================================
+
+import time
+from utils.labels import *
+from ServerHandlers import *
+
+class Mouse_Server:
+
+ """ Mouse Server
+ Defines all mouse behaviors.
+ Clicks and coordinates.
+ """
+
+ #Initialize the class
+ def __init__(self):
+
+ self.mouse = Mouse()
+ self.labels = Labels()
+ self.timer = time
+ self.timerclick = 0
+
+ self.fg_dbclick = False
+ self.fg_move = True
+ self.x = 0
+ self.y = 0
+
+ #Executes the action requested by the Service Manager
+ def execute(self, command):
+
+ self.mouse_counter_lclick()
+
+ if (command == self.labels.CLICK):
+ self.mouse_click()
+ elif (command == self.labels.DOUBLE_CLICK):
+ self.mouse_press_dbclick()
+ elif (command == self.labels.TRIPLE_CLICK):
+ self.mouse_release_dbclick()
+ elif (command == self.labels.LEFT_CLICK):
+ self.mouse_lclick()
+ elif (command == self.labels.MIDDLE_CLICK):
+ self.mouse_mclick()
+ elif (command == self.labels.RIGHT_CLICK):
+ self.mouse_rclick()
+ elif (command[0] == "#"):
+ self.mouse_fator(command)
+ else:
+ self.mouse_move(command)
+
+ #Gets the time the mouse pointer is pressed. If It is greater than (or equal to) 2s, The Mouse Left Click is activated.
+ def mouse_counter_lclick(self):
+
+ if ((not self.fg_move) and ((int(self.timer.time()) - self.timerclick) >= 2)):
+ self.mouse.right_click(True)
+ self.mouse.right_click(False)
+ self.timerclick = 0
+ self.fg_move = True
+
+ #Mouse Pointer - Single Click
+ def mouse_click(self):
+ self.timerclick = int(self.timer.time())
+ self.fg_move = False
+
+ #Mouse Pointer - Double Click
+ def mouse_press_dbclick(self):
+ self.mouse.left_click(True)
+ self.fg_dbclick = True
+
+ #Mouse Pointer - Released after a Double Click
+ def mouse_release_dbclick(self):
+ if self.fg_dbclick:
+ self.mouse.left_click(False)
+ self.fg_dbclick = False
+
+ #Mouse Left Click
+ def mouse_lclick(self):
+ self.mouse.left_click()
+
+ #Mouse Middle Click
+ def mouse_mclick(self):
+ self.mouse.middle_click()
+
+ #Mouse Right Click
+ def mouse_rclick(self):
+ self.mouse.right_click()
+
+ #Sets the factor of the Mouse Pointer Move
+ def mouse_fator(self, command):
+ num = ""
+ for i in range(1, len(command)):
+ num = num + command(i)
+
+ self.mouse.set_fator(int(num))
+
+ #Moves the Mouse Pointer
+ def mouse_move(self, command):
+ coord = command.split(",")
+
+ i = int(coord[0]) - self.x
+ if ((abs(i) == 1) or (abs(i) >= 20)):
+ i = 0
+
+ j = int(coord[1]) - self.y
+ if ((abs(j) == 1) or (abs(j) >= 20)):
+ j = 0
+
+ if not ((i == 0) and (j == 0)):
+ if ((i >= 4) or (j >= 4)):
+ self.fg_move = True
+ self.mouse.position(i, j)
+
+ self.x = int(coord[0])
+ self.y = int(coord[1])
+
+ def clean_up_mouse(self):
+ self.mouse.clean_up_mouse()
+
+class KeyBoard_Server:
+
+ """ Keyboard Server
+ Defines all keyboard behaviors.
+ Map keys and events.
+ """
+
+ def __init__(self):
+ self.keyboard = Keyboard()
+ self.shift_flag = False
+ self.control_flag = False
+ self.keys = []
+
+ # execute key command
+ def execute(self, command):
+
+ print "\n", command
+
+ if(command == 'F8'):
+ self.keyboard.reproduce_key_press('Control_L')
+ self.keyboard.reproduce_key_press('z')
+ self.keyboard.reproduce_key_release('z')
+ self.keyboard.reproduce_key_release('Control_L')
+ elif(command == 'ISO_Level3_Shift'):
+ self.keyboard.reproduce_key_press('Escape')
+ self.keyboard.reproduce_key_release('Escape')
+ pass
+ elif(command == 'Control_R'):
+ self.control_flag = True
+ self.keyboard.reproduce_key_press('Control_R')
+ self.keys.append(command)
+ elif(command == 'Shift_L'):
+ self.shift_flag = True
+ self.keyboard.reproduce_key_press('Shift_L')
+ self.keys.append(command)
+ elif(command == 'F7'):
+ self.keyboard.reproduce_key_press('Control_L')
+ self.keyboard.reproduce_key_press('y')
+ self.keyboard.reproduce_key_release('y')
+ self.keyboard.reproduce_key_release('Control_L')
+ else:
+
+ self.keyboard.reproduce_key_press(command)
+ self.keyboard.reproduce_key_release(command)
+
+ if self.shift_flag:
+ self.keyboard.reproduce_key_release('Shift_L')
+ self.keys.remove('Shift_L')
+ self.shift_flag = False
+ elif self.control_flag:
+ self.keyboard.reproduce_key_release('Control_R')
+ self.keys.remove('Control_R')
+ self.control_flag = False
+
+ # clean all keys pressed
+ def clean_up_keyboard(self):
+ print "\nkeys -> ", self.keys
+ list = self.keys
+ print "\nlist ->", list
+ for i in list:
+ self.keyboard.reproduce_key_release(i)
+ self.keys.remove(i)
+ print "\nkey --> ", i, " removed."
+
+ print self.keys