File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,22 +9,30 @@ enum MouseValue {
99 Right = 2
1010}
1111
12+ enum MouseState {
13+ MouseDown = 0 ,
14+ MouseUp = 1
15+ }
16+
1217type mouseHandler = ( output : ArrayBuffer ) => void ;
1318
14- const click_events : ( keyof HTMLVideoElementEventMap ) [ ] = [ 'click ' , 'auxclick ' ] ;
19+ const click_events : ( keyof HTMLVideoElementEventMap ) [ ] = [ 'mousedown ' , 'mouseup ' ] ;
1520
1621export function handleClick ( callback : mouseHandler ) {
1722 const handler = ( event : Event ) => {
18- if ( ! ( event instanceof PointerEvent ) ) return ;
23+ if ( ! ( event instanceof MouseEvent ) ) return ;
1924 console . log ( `Click ${ event . type } : ${ event . button } ` ) ;
2025
21- const value = event . button as MouseValue ;
26+ const btnCLicked = event . button as MouseValue ;
2227
23- const buf = new ArrayBuffer ( 2 )
28+ const buf = new ArrayBuffer ( 3 )
2429 const view = new Uint8Array ( buf ) ;
2530
31+ const stateBtn = event . type === "mousedown" ? MouseState . MouseDown : MouseState . MouseUp
32+
2633 view [ 0 ] = MouseType . Click
27- view [ 1 ] = value
34+ view [ 1 ] = btnCLicked
35+ view [ 2 ] = stateBtn
2836
2937 return callback ( buf ) ;
3038 } ;
Original file line number Diff line number Diff line change @@ -53,16 +53,27 @@ func HandleMouse(d *webrtc.DataChannel) error {
5353 return
5454 }
5555
56+ btnState , err := msgBuf .ReadByte ()
57+
58+ if err != nil {
59+ return
60+ }
61+
62+ var state string
63+
64+ if btnState == mouseDown {
65+ state = "down"
66+ } else if btnState == mouseUp {
67+ state = "up"
68+ }
69+
5670 switch clickBtn {
5771 case mouseLeft :
58- // TODO: make left click persist
59- robotgo .Click ()
72+ robotgo .Toggle ("left" , state )
6073 case mouseCentral :
61- // TODO: make middle click persist
62- robotgo .Click ("center" )
74+ robotgo .Toggle ("center" , state )
6375 case mouseRight :
64- // TODO: make right click persist
65- robotgo .Click ("right" )
76+ robotgo .Toggle ("right" , state )
6677 }
6778
6879 } else if msgType == typeMsgMove { // Handle move event
Original file line number Diff line number Diff line change 99 mouseLeft uint8 = iota
1010 mouseCentral
1111 mouseRight
12+ )
13+
14+ const (
15+ mouseDown uint8 = iota
16+ mouseUp
1217)
You can’t perform that action at this time.
0 commit comments