func sendMouseEvent(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) { e := mouse.Event{ X: float32(_GET_X_LPARAM(lParam)), Y: float32(_GET_Y_LPARAM(lParam)), Modifiers: keyModifiers(), } switch uMsg { case _WM_MOUSEMOVE: e.Direction = mouse.DirNone case _WM_LBUTTONDOWN, _WM_MBUTTONDOWN, _WM_RBUTTONDOWN: e.Direction = mouse.DirPress case _WM_LBUTTONUP, _WM_MBUTTONUP, _WM_RBUTTONUP: e.Direction = mouse.DirRelease case _WM_MOUSEWHEEL: // TODO: On a trackpad, a scroll can be a drawn-out affair with a // distinct beginning and end. Should the intermediate events be // DirNone? e.Direction = mouse.DirStep default: panic("sendMouseEvent() called on non-mouse message") } switch uMsg { case _WM_MOUSEMOVE: // No-op. case _WM_LBUTTONDOWN, _WM_LBUTTONUP: e.Button = mouse.ButtonLeft case _WM_MBUTTONDOWN, _WM_MBUTTONUP: e.Button = mouse.ButtonMiddle case _WM_RBUTTONDOWN, _WM_RBUTTONUP: e.Button = mouse.ButtonRight case _WM_MOUSEWHEEL: // TODO: handle horizontal scrolling delta := _GET_WHEEL_DELTA_WPARAM(wParam) / _WHEEL_DELTA switch { case delta > 0: e.Button = mouse.ButtonWheelUp case delta < 0: e.Button = mouse.ButtonWheelDown delta = -delta default: return } for delta > 0 { MouseEvent(hwnd, e) delta-- } return } MouseEvent(hwnd, e) return 0 }
func sendMouseEvent(hwnd HWND, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) { e := mouse.Event{ X: float32(_GET_X_LPARAM(lParam)), Y: float32(_GET_Y_LPARAM(lParam)), Modifiers: keyModifiers(), } switch uMsg { case _WM_MOUSEMOVE, _WM_MOUSEWHEEL: e.Direction = mouse.DirNone case _WM_LBUTTONDOWN, _WM_MBUTTONDOWN, _WM_RBUTTONDOWN: e.Direction = mouse.DirPress case _WM_LBUTTONUP, _WM_MBUTTONUP, _WM_RBUTTONUP: e.Direction = mouse.DirRelease default: panic("sendMouseEvent() called on non-mouse message") } switch uMsg { case _WM_MOUSEMOVE: switch { case wParam&_MK_LBUTTON == _MK_LBUTTON: e.Button = mouse.ButtonLeft case wParam&_MK_MBUTTON == _MK_MBUTTON: e.Button = mouse.ButtonMiddle case wParam&_MK_RBUTTON == _MK_RBUTTON: e.Button = mouse.ButtonRight default: // TODO: send move events when no buttons are held down? return 0 } case _WM_LBUTTONDOWN, _WM_LBUTTONUP: e.Button = mouse.ButtonLeft case _WM_MBUTTONDOWN, _WM_MBUTTONUP: e.Button = mouse.ButtonMiddle case _WM_RBUTTONDOWN, _WM_RBUTTONUP: e.Button = mouse.ButtonRight case _WM_MOUSEWHEEL: delta := _GET_WHEEL_DELTA_WPARAM(wParam) / _WHEEL_DELTA switch { case delta > 0: e.Button = mouse.ButtonWheelUp case delta < 0: e.Button = mouse.ButtonWheelDown delta = -delta default: return } for delta > 0 { MouseEvent(hwnd, e) delta-- } return } MouseEvent(hwnd, e) return 0 }