@@ -846,8 +846,8 @@ export function initGamepad() {
846846
847847 const longPressTimeouts = { } ;
848848 const longPressIntervals = { } ;
849- const repeatDelay = 500 ;
850- const repeatInterval = 150 ;
849+ const repeatDelay = 250 ;
850+ const repeatInterval = 50 ;
851851
852852 // Listen for gamepad connection events
853853 window . addEventListener ( 'gamepadconnected' , ( event ) => {
@@ -887,37 +887,89 @@ export function initGamepad() {
887887 if ( ! buttonStates [ 'leftStickLeft' ] ) {
888888 buttonStates [ 'leftStickLeft' ] = true ;
889889 handleGameControllerButtonPress ( 14 ) ; // Left
890+ longPressTimeouts [ 'leftStickLeft' ] = setTimeout ( ( ) => {
891+ longPressIntervals [ 'leftStickLeft' ] = setInterval ( ( ) => {
892+ handleGameControllerButtonPress ( 14 ) ;
893+ } , repeatInterval ) ;
894+ } , repeatDelay ) ;
890895 }
891896 } else if ( buttonStates [ 'leftStickLeft' ] ) {
892897 buttonStates [ 'leftStickLeft' ] = false ;
898+ if ( longPressTimeouts [ 'leftStickLeft' ] ) {
899+ clearTimeout ( longPressTimeouts [ 'leftStickLeft' ] ) ;
900+ delete longPressTimeouts [ 'leftStickLeft' ] ;
901+ }
902+ if ( longPressIntervals [ 'leftStickLeft' ] ) {
903+ clearInterval ( longPressIntervals [ 'leftStickLeft' ] ) ;
904+ delete longPressIntervals [ 'leftStickLeft' ] ;
905+ }
893906 }
894907
895908 if ( leftStickX > threshold ) {
896909 if ( ! buttonStates [ 'leftStickRight' ] ) {
897910 buttonStates [ 'leftStickRight' ] = true ;
898911 handleGameControllerButtonPress ( 15 ) ; // Right
912+ longPressTimeouts [ 'leftStickRight' ] = setTimeout ( ( ) => {
913+ longPressIntervals [ 'leftStickRight' ] = setInterval ( ( ) => {
914+ handleGameControllerButtonPress ( 15 ) ;
915+ } , repeatInterval ) ;
916+ } , repeatDelay ) ;
899917 }
900918 } else if ( buttonStates [ 'leftStickRight' ] ) {
901919 buttonStates [ 'leftStickRight' ] = false ;
920+ if ( longPressTimeouts [ 'leftStickRight' ] ) {
921+ clearTimeout ( longPressTimeouts [ 'leftStickRight' ] ) ;
922+ delete longPressTimeouts [ 'leftStickRight' ] ;
923+ }
924+ if ( longPressIntervals [ 'leftStickRight' ] ) {
925+ clearInterval ( longPressIntervals [ 'leftStickRight' ] ) ;
926+ delete longPressIntervals [ 'leftStickRight' ] ;
927+ }
902928 }
903929
904930 // Left stick vertical (up/down)
905931 if ( leftStickY < - threshold ) {
906932 if ( ! buttonStates [ 'leftStickUp' ] ) {
907933 buttonStates [ 'leftStickUp' ] = true ;
908934 handleGameControllerButtonPress ( 12 ) ; // Up
935+ longPressTimeouts [ 'leftStickUp' ] = setTimeout ( ( ) => {
936+ longPressIntervals [ 'leftStickUp' ] = setInterval ( ( ) => {
937+ handleGameControllerButtonPress ( 12 ) ;
938+ } , repeatInterval ) ;
939+ } , repeatDelay ) ;
909940 }
910941 } else if ( buttonStates [ 'leftStickUp' ] ) {
911942 buttonStates [ 'leftStickUp' ] = false ;
943+ if ( longPressTimeouts [ 'leftStickUp' ] ) {
944+ clearTimeout ( longPressTimeouts [ 'leftStickUp' ] ) ;
945+ delete longPressTimeouts [ 'leftStickUp' ] ;
946+ }
947+ if ( longPressIntervals [ 'leftStickUp' ] ) {
948+ clearInterval ( longPressIntervals [ 'leftStickUp' ] ) ;
949+ delete longPressIntervals [ 'leftStickUp' ] ;
950+ }
912951 }
913952
914953 if ( leftStickY > threshold ) {
915954 if ( ! buttonStates [ 'leftStickDown' ] ) {
916955 buttonStates [ 'leftStickDown' ] = true ;
917956 handleGameControllerButtonPress ( 13 ) ; // Down
957+ longPressTimeouts [ 'leftStickDown' ] = setTimeout ( ( ) => {
958+ longPressIntervals [ 'leftStickDown' ] = setInterval ( ( ) => {
959+ handleGameControllerButtonPress ( 13 ) ;
960+ } , repeatInterval ) ;
961+ } , repeatDelay ) ;
918962 }
919963 } else if ( buttonStates [ 'leftStickDown' ] ) {
920964 buttonStates [ 'leftStickDown' ] = false ;
965+ if ( longPressTimeouts [ 'leftStickDown' ] ) {
966+ clearTimeout ( longPressTimeouts [ 'leftStickDown' ] ) ;
967+ delete longPressTimeouts [ 'leftStickDown' ] ;
968+ }
969+ if ( longPressIntervals [ 'leftStickDown' ] ) {
970+ clearInterval ( longPressIntervals [ 'leftStickDown' ] ) ;
971+ delete longPressIntervals [ 'leftStickDown' ] ;
972+ }
921973 }
922974
923975 [ 0 , 1 , 2 , 3 , 4 , 5 , 8 , 12 , 13 , 14 , 15 ] . forEach ( ( buttonIndex ) => {
0 commit comments