@@ -17,10 +17,11 @@ public MouseHandler(HidHandler hidHandler, FileStream mouseFileStream, string st
1717 DeviceStream = mouseFileStream ;
1818 new Thread ( ( ) =>
1919 {
20- // Enable Z axis via magic sample rate
21- mouseFileStream . Write ( new byte [ ] { 0xf3 , 200 , 0xf3 , 100 , 0xf3 , 80 } ) ;
20+ // https://wiki.osdev.org/PS/2_Mouse
21+ // Enable Z axis & side buttons (four, five) via magic sample rate
22+ mouseFileStream . Write ( new byte [ ] { 0xf3 , 200 , 0xf3 , 200 , 0xf3 , 80 } ) ;
2223 mouseFileStream . Flush ( ) ;
23-
24+
2425 var skip = true ;
2526 while ( Active )
2627 {
@@ -38,12 +39,31 @@ public MouseHandler(HidHandler hidHandler, FileStream mouseFileStream, string st
3839 continue ;
3940 }
4041
42+ var fourButton = false ;
43+ var fiveButton = false ;
44+ int wheel ;
45+
4146 MouseLock . EnterReadLock ( ) ;
4247 try
4348 {
4449 mouseSbyteArray [ 1 ] = Mouse . InvertMouseX ? Convert . ToSByte ( Convert . ToInt32 ( mouseSbyteArray [ 1 ] ) * - 1 ) : mouseSbyteArray [ 1 ] ;
4550 mouseSbyteArray [ 2 ] = Mouse . InvertMouseY ? mouseSbyteArray [ 2 ] : Convert . ToSByte ( Convert . ToInt32 ( mouseSbyteArray [ 2 ] ) * - 1 ) ;
46- mouseSbyteArray [ 3 ] = Mouse . InvertMouseWheel ? mouseSbyteArray [ 3 ] : Convert . ToSByte ( Convert . ToInt32 ( mouseSbyteArray [ 3 ] ) * - 1 ) ;
51+
52+ // future proofing
53+ if ( mouseSbyteArray . Length != 4 )
54+ {
55+ mouseSbyteArray [ 3 ] = Mouse . InvertMouseWheel ? mouseSbyteArray [ 3 ] : Convert . ToSByte ( Convert . ToInt32 ( mouseSbyteArray [ 3 ] ) * - 1 ) ;
56+ wheel = Convert . ToInt32 ( mouseSbyteArray [ 3 ] ) ;
57+ }
58+ else
59+ {
60+ fourButton = ( mouseSbyteArray [ 3 ] & 0x10 ) > 0 ;
61+ fiveButton = ( mouseSbyteArray [ 3 ] & 0x20 ) > 0 ;
62+
63+ int z = ( mouseSbyteArray [ 3 ] & 0xF ) > 7 ? ( mouseSbyteArray [ 3 ] & 0xF ) - 16 : ( mouseSbyteArray [ 3 ] & 0xF ) ;
64+
65+ wheel = Mouse . InvertMouseWheel ? z : z * - 1 ;
66+ }
4767 }
4868 finally
4969 {
@@ -55,10 +75,12 @@ public MouseHandler(HidHandler hidHandler, FileStream mouseFileStream, string st
5575 LeftButton = ( mouseSbyteArray [ 0 ] & 0x1 ) > 0 ,
5676 RightButton = ( mouseSbyteArray [ 0 ] & 0x2 ) > 0 ,
5777 MiddleButton = ( mouseSbyteArray [ 0 ] & 0x4 ) > 0 ,
78+ FourButton = fourButton ,
79+ FiveButton = fiveButton ,
5880 X = Convert . ToInt32 ( mouseSbyteArray [ 1 ] ) ,
5981 Y = Convert . ToInt32 ( mouseSbyteArray [ 2 ] ) ,
60- Wheel = Convert . ToInt32 ( mouseSbyteArray [ 3 ] )
61- } ;
82+ Wheel = wheel
83+ } ;
6284
6385 MouseLock . EnterWriteLock ( ) ;
6486 try
0 commit comments