in reply to SDL Events hold key down
I would just set a certain amount of "motion ( dx or dy )" to each key press, and set up a "repeat interval for the keys"). So when you hold the key down, you will get a succesion of events, which stop when the key is released.
Here is a super simple example just to give you the idea. Instead of printing the repeating key code, just assign your motion.
#!/usr/bin/perl use SDL::App; use SDL::Event; use SDL; ### Create A new Application window my $app = new SDL::App -width => 400, -height => 400; ### A simple event handler hash my $events = { SDL_KEYDOWN() => sub { my ($e) = @_; exit(0) if ( $e->key_sym() == SDLK_ESCAPE ); print $e->key_sym(),"\n"; }, SDL_QUIT() => sub { exit(); }, }; my $eventkr = new SDL::Event; $eventkr->set_key_repeat( 10, 10); ### Loop & process the events $app->loop($events); #$app->loop(); #no events, must kill to exit
|
|---|