[sdl2] long-click sticky key functional

This commit is contained in:
Gwenhael Le Moine 2024-09-07 10:37:16 +02:00
parent a25ca2de89
commit 2e22cafc03
No known key found for this signature in database
GPG key ID: FDFE3669426707A7

View file

@ -1042,18 +1042,21 @@ void sdl_get_event( void )
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
hpkey = mouse_click_to_hpkey( event.button.x, event.button.y ); hpkey = mouse_click_to_hpkey( event.button.x, event.button.y );
if ( sdl_press_key( hpkey ) != -1 ) { if ( sdl_press_key( hpkey ) != -1 ) {
lasthpkey = hpkey; if ( lasthpkey == -1 ) {
// Start timer lasthpkey = hpkey;
lastticks = SDL_GetTicks(); // Start timer
lastticks = SDL_GetTicks();
} else
lasthpkey = lastticks = -1;
} }
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
hpkey = mouse_click_to_hpkey( event.button.x, event.button.y ); hpkey = mouse_click_to_hpkey( event.button.x, event.button.y );
if ( lasthpkey != hpkey || lastticks == -1 || ( SDL_GetTicks() - lastticks < 750 ) ) { if ( lasthpkey != hpkey || lastticks == -1 || ( SDL_GetTicks() - lastticks < 750 ) )
lasthpkey = lastticks = -1;
sdl_release_key( hpkey ); sdl_release_key( hpkey );
}
lasthpkey = lastticks = -1;
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN: