1 # -*- coding: utf-8 -*-
3 # ****************************************************************************
4 # Copyright (c) 2008 INdT/Fucapi.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # ============================================================================
19 # Project Name : PC Remote
20 # Author : Nilson Silva, Jonatas Isvi, Andre Portela
21 # Email : fergus.mao@gmail.com, jonatas.nona@gmail.com,
22 # andre_portela_@hotmail.com
23 # Reviewer : Jônatas Isvi
27 # Description : Mouse Server, Keyboard Server
28 # ============================================================================
31 from utils.labels import *
32 from ServerHandlers import *
37 Defines all mouse behaviors.
38 Clicks and coordinates.
45 self.labels = Labels()
49 self.fg_dbclick = False
54 #Executes the action requested by the Service Manager
55 def execute(self, command):
57 self.mouse_counter_lclick()
59 if (command == self.labels.CLICK):
61 elif (command == self.labels.DOUBLE_CLICK):
62 self.mouse_press_dbclick()
63 elif (command == self.labels.TRIPLE_CLICK):
64 self.mouse_release_dbclick()
65 elif (command == self.labels.LEFT_CLICK):
67 elif (command == self.labels.MIDDLE_CLICK):
69 elif (command == self.labels.RIGHT_CLICK):
71 elif (command[0] == "#"):
72 self.mouse_fator(command)
74 self.mouse_move(command)
76 #Gets the time the mouse pointer is pressed. If It is greater than (or equal to) 2s, The Mouse Left Click is activated.
77 def mouse_counter_lclick(self):
79 if ((not self.fg_move) and ((int(self.timer.time()) - self.timerclick) >= 2)):
80 self.mouse.right_click(True)
81 self.mouse.right_click(False)
85 #Mouse Pointer - Single Click
86 def mouse_click(self):
87 self.timerclick = int(self.timer.time())
90 #Mouse Pointer - Double Click
91 def mouse_press_dbclick(self):
92 self.mouse.left_click(True)
93 self.fg_dbclick = True
95 #Mouse Pointer - Released after a Double Click
96 def mouse_release_dbclick(self):
98 self.mouse.left_click(False)
99 self.fg_dbclick = False
102 def mouse_lclick(self):
103 self.mouse.left_click()
106 def mouse_mclick(self):
107 self.mouse.middle_click()
110 def mouse_rclick(self):
111 self.mouse.right_click()
113 #Sets the factor of the Mouse Pointer Move
114 def mouse_fator(self, command):
116 for i in range(1, len(command)):
117 num = num + command(i)
119 self.mouse.set_fator(int(num))
121 #Moves the Mouse Pointer
122 def mouse_move(self, command):
123 coord = command.split(",")
125 i = int(coord[0]) - self.x
126 if ((abs(i) == 1) or (abs(i) >= 20)):
129 j = int(coord[1]) - self.y
130 if ((abs(j) == 1) or (abs(j) >= 20)):
133 if not ((i == 0) and (j == 0)):
134 if ((i >= 4) or (j >= 4)):
136 self.mouse.position(i, j)
138 self.x = int(coord[0])
139 self.y = int(coord[1])
141 def clean_up_mouse(self):
142 self.mouse.clean_up_mouse()
144 class KeyBoard_Server:
147 Defines all keyboard behaviors.
152 self.keyboard = Keyboard()
153 self.shift_flag = False
154 self.control_flag = False
157 # execute key command
158 def execute(self, command):
163 self.keyboard.reproduce_key_press('Control_L')
164 self.keyboard.reproduce_key_press('z')
165 self.keyboard.reproduce_key_release('z')
166 self.keyboard.reproduce_key_release('Control_L')
167 elif(command == 'ISO_Level3_Shift'):
168 self.keyboard.reproduce_key_press('Escape')
169 self.keyboard.reproduce_key_release('Escape')
171 elif(command == 'Control_R'):
172 self.control_flag = True
173 self.keyboard.reproduce_key_press('Control_R')
174 self.keys.append(command)
175 elif(command == 'Shift_L'):
176 self.shift_flag = True
177 self.keyboard.reproduce_key_press('Shift_L')
178 self.keys.append(command)
179 elif(command == 'F7'):
180 self.keyboard.reproduce_key_press('Control_L')
181 self.keyboard.reproduce_key_press('y')
182 self.keyboard.reproduce_key_release('y')
183 self.keyboard.reproduce_key_release('Control_L')
186 self.keyboard.reproduce_key_press(command)
187 self.keyboard.reproduce_key_release(command)
190 self.keyboard.reproduce_key_release('Shift_L')
191 self.keys.remove('Shift_L')
192 self.shift_flag = False
193 elif self.control_flag:
194 self.keyboard.reproduce_key_release('Control_R')
195 self.keys.remove('Control_R')
196 self.control_flag = False
198 # clean all keys pressed
199 def clean_up_keyboard(self):
200 print "\nkeys -> ", self.keys
202 print "\nlist ->", list
204 self.keyboard.reproduce_key_release(i)
206 print "\nkey --> ", i, " removed."