Skip to content

Commit a1f9afa

Browse files
committed
onPointerEvent: handle 4, 5 mouse buttons based on INPUT_EVENT_MOUSEX event
1 parent b8ff413 commit a1f9afa

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class MyRDPFactory(rdp.ServerFactory):
236236
@summary: Event call on mouse event
237237
@param x: x position
238238
@param y: y position
239-
@param button: 1, 2 or 3 button
239+
@param button: 1, 2, 3, 4 or 5 button
240240
@param isPressed: True if mouse button is pressed
241241
@see: rdp.RDPServerObserver.onPointerEvent
242242
"""

bin/rdpy-rdpmitm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def onPointerEvent(self, x, y, button, isPressed):
129129
@summary: Event call on mouse event
130130
@param x: {int} x position
131131
@param y: {int} y position
132-
@param button: {int} 1, 2 or 3 button
132+
@param button: {int} 1, 2, 3, 4 or 5 button
133133
@param isPressed: {bool} True if mouse button is pressed
134134
@see: rdp.RDPServerObserver.onPointerEvent
135135
"""

rdpy/protocol/rdp/pdu/data.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,16 @@ class PointerFlag(object):
160160
PTRFLAGS_BUTTON1 = 0x1000
161161
PTRFLAGS_BUTTON2 = 0x2000
162162
PTRFLAGS_BUTTON3 = 0x4000
163-
163+
164+
class PointerExFlag(object):
165+
"""
166+
@summary: Use in Pointer event
167+
@see: https://msdn.microsoft.com/en-us/library/cc240587.aspx
168+
"""
169+
PTRXFLAGS_DOWN = 0x8000
170+
PTRXFLAGS_BUTTON1 = 0x0001
171+
PTRXFLAGS_BUTTON2 = 0x0002
172+
164173
class KeyboardFlag(object):
165174
"""
166175
@summary: Use in scan code key event

rdpy/protocol/rdp/rdp.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,35 @@ def sendPointerEvent(self, x, y, button, isPressed):
228228
return
229229

230230
try:
231-
event = pdu.data.PointerEvent()
232-
if isPressed:
233-
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_DOWN
234-
235-
if button == 1:
236-
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON1
237-
elif button == 2:
238-
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON2
239-
elif button == 3:
240-
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON3
231+
if button == 4 or button == 5:
232+
event = pdu.data.PointerExEvent()
233+
if isPressed:
234+
event.pointerFlags.value |= pdu.data.PointerExFlag.PTRXFLAGS_DOWN
235+
236+
if button == 4:
237+
event.pointerFlags.value |= pdu.data.PointerExFlag.PTRXFLAGS_BUTTON1
238+
elif button == 5:
239+
event.pointerFlags.value |= pdu.data.PointerExFlag.PTRXFLAGS_BUTTON2
240+
241241
else:
242-
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_MOVE
242+
event = pdu.data.PointerEvent()
243+
if isPressed:
244+
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_DOWN
245+
246+
if button == 1:
247+
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON1
248+
elif button == 2:
249+
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON2
250+
elif button == 3:
251+
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_BUTTON3
252+
else:
253+
event.pointerFlags.value |= pdu.data.PointerFlag.PTRFLAGS_MOVE
243254

244-
#position
255+
# position
245256
event.xPos.value = x
246257
event.yPos.value = y
247258

248-
#send proper event
259+
# send proper event
249260
self._pduLayer.sendInputEvents([event])
250261

251262
except InvalidValue:
@@ -500,7 +511,7 @@ def onSlowPathInput(self, slowPathInputEvents):
500511
#unicode
501512
elif event.messageType.value == pdu.data.InputMessageType.INPUT_EVENT_UNICODE:
502513
observer.onKeyEventUnicode(event.slowPathInputData.unicode.value, not (event.slowPathInputData.keyboardFlags.value & pdu.data.KeyboardFlag.KBDFLAGS_RELEASE))
503-
#mouse event
514+
#mouse events
504515
elif event.messageType.value == pdu.data.InputMessageType.INPUT_EVENT_MOUSE:
505516
isPressed = event.slowPathInputData.pointerFlags.value & pdu.data.PointerFlag.PTRFLAGS_DOWN
506517
button = 0
@@ -511,6 +522,15 @@ def onSlowPathInput(self, slowPathInputEvents):
511522
elif event.slowPathInputData.pointerFlags.value & pdu.data.PointerFlag.PTRFLAGS_BUTTON3:
512523
button = 3
513524
observer.onPointerEvent(event.slowPathInputData.xPos.value, event.slowPathInputData.yPos.value, button, isPressed)
525+
elif event.messageType.value == pdu.data.InputMessageType.INPUT_EVENT_MOUSEX:
526+
isPressed = event.slowPathInputData.pointerFlags.value & pdu.data.PointerExFlag.PTRXFLAGS_DOWN
527+
button = 0
528+
if event.slowPathInputData.pointerFlags.value & pdu.data.PointerExFlag.PTRXFLAGS_BUTTON1:
529+
button = 4
530+
elif event.slowPathInputData.pointerFlags.value & pdu.data.PointerExFlag.PTRXFLAGS_BUTTON2:
531+
button = 5
532+
observer.onPointerEvent(event.slowPathInputData.xPos.value, event.slowPathInputData.yPos.value, button, isPressed)
533+
514534

515535
def sendUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
516536
"""
@@ -698,7 +718,7 @@ def onPointerEvent(self, x, y, button, isPressed):
698718
@summary: Event call on mouse event
699719
@param x: x position
700720
@param y: y position
701-
@param button: 1, 2 or 3 button
721+
@param button: 1, 2, 3, 4 or 5 button
702722
@param isPressed: True if mouse button is pressed
703723
"""
704724
raise CallPureVirtualFuntion("%s:%s defined by interface %s"%(self.__class__, "onPointerEvent", "RDPServerObserver"))

0 commit comments

Comments
 (0)