views:

17

answers:

0

I'm using teamplayer, which lets you connect more mice to your computer to be used simultaneously. I'm also using pyHook to capture mouse events, with the following code:

import pyHook
import pythoncom

def onclick(event):
  # called when mouse events are received
  print 'MessageName:',event.MessageName
  print 'Message:',event.Message
  print 'Time:',event.Time
  print 'WindowName:',event.WindowName
  print 'Position:',event.Position
  print '---'
  return True

hm = pyHook.HookManager()
hm.MouseLeftDown = onclick
hm.MouseLeftUp = onclick
hm.HookMouse()
pythoncom.PumpMessages()

The code works fine without teamplayer - it detects the mouse button down and up accurately. If I start teamplayer while the program is running, then it continues to work well, this time detecting clicks from both mice accurately.

However, if I start the program after teamplayer is started, then every mouseclick becomes double:

MessageName: mouse left down
Message: 513
Time: 7231317
WindowName: None
Position: (673, 367)
---
MessageName: mouse left down
Message: 513
Time: 7231317
WindowName: None
Position: (673, 367)
---
MessageName: mouse left up
Message: 514
Time: 7231379
WindowName: None
Position: (673, 367)
---
MessageName: mouse left up
Message: 514
Time: 7231379
WindowName: None
Position: (673, 367)

This would be OK - I could detect clicks with the same timestamp and ignore the second one. However, when I click with a different mouse, the pattern is strange:

MessageName: mouse left down
Message: 513
Time: 7305916
WindowName: C:\Python25\python.exe
Position: (569, 306)
---
MessageName: mouse left down
Message: 513
Time: 7305916
WindowName: C:\Python25\python.exe
Position: (722, 365)
---
MessageName: mouse left up
Message: 514
Time: 7309598
WindowName: C:\Python25\python.exe
Position: (722, 365)
---
MessageName: mouse left up
Message: 514
Time: 7309598
WindowName: C:\Python25\python.exe
Position: (722, 365)

That is, the first down event uses the coordinates from the last up event! The problem is also that the wrong event is first, making it harder to detect the correct one (I can't just say "ignore the first event", because if teamplayer is off or only one mouse is connected, that's the only one!)

Any ideas as to why this might be happening, and what I can do to get normal mouse events?