Make sure that the keystate received by the WM_XBUTTONUP and WM_XBUTTONDOWN matches the message. In X, the keystate is changed after the message is processed. In Windows, it is changed before.