Commit | Line | Data |
8fde61e3 |
1 | #!/usr/bin/env perl |
2 | |
3 | use SDL; |
4 | use SDL::App; |
5 | use SDL::Event; |
6 | |
7 | my %options; |
8 | |
9 | die <<USAGE if ( in $ARGV[0], qw/ -? -h --help /); |
10 | usage: $0 [-hw] [-fullscreen] [-width 640] [-height 480] [-bpp 24] |
11 | USAGE |
12 | |
13 | for ( 0 .. @ARGV-1 ) |
14 | { |
15 | $options{$ARGV[$_]} = $ARGV[$_ + 1] || 1; |
16 | } |
17 | |
18 | $options{-flags} = SDL_SWSURFACE; |
19 | $options{-flags} |= SDL_HWPALETTE if ( $options{-hw} ); |
20 | $options{-flags} |= SDL_FULLSCREEN if ( $options{-fullscreen} ); |
21 | |
22 | $options{-title} = $0; |
23 | |
24 | $options{-width} ||= 640; |
25 | $options{-height} ||= 480; |
26 | $options{-depth} ||= $options{-bpp} || 24; |
27 | |
28 | my $app = new SDL::App %options; |
29 | |
30 | # SDL::EventState(SDL_KEYUP,SDL_DISABLE); |
31 | |
32 | sub print_modifiers |
33 | { |
34 | $mod = SDL::GetModState(); |
35 | |
36 | print " modifiers:", |
37 | ($mod & KMOD_LSHIFT) ? " LSHIFT" : "", |
38 | ($mod & KMOD_RSHIFT) ? " RSHIFT" : "", |
39 | ($mod & KMOD_LCTRL) ? " LCTRL" : "", |
40 | ($mod & KMOD_RCTRL) ? " RCTRL" : "", |
41 | ($mod & KMOD_LALT) ? " LALT" : "", |
42 | ($mod & KMOD_RALT) ? " RALT" : "", |
43 | ($mod & KMOD_LMETA) ? " LMETA" : "", |
44 | ($mod & KMOD_RMETA) ? " RMETA" : "", |
45 | ($mod & KMOD_CAPS) ? " CAPS" : "", |
46 | ($mod & KMOD_NUM) ? " NUM" : "", |
47 | ($mod & KMOD_MODE) ? " MODE" : "", |
48 | "\n" ; |
49 | } |
50 | |
51 | sub print_key |
52 | { |
53 | my ($e) = @_; |
54 | |
55 | print "pressed " if (SDL::KeyEventState($e) == SDL_PRESSED); |
56 | print "released " if ( SDL::KeyEventState($e) == SDL_RELEASED); |
57 | |
58 | my $sym = SDL::KeyEventSym($e); |
59 | |
60 | if ($sym) { |
61 | print SDL::GetKeyName($sym); |
62 | } else { |
63 | printf "Unknown Key (scancode = %d) ", SDL::KeyEventScanCode($e); |
64 | } |
65 | |
66 | } |
67 | |
68 | my $event = new SDL::Event; |
69 | |
70 | my $done = 0; |
71 | |
72 | $process_keys = sub { |
73 | print_key($_[0]); |
74 | print_modifiers(); |
75 | }; |
76 | |
77 | my %events = ( |
78 | SDL_KEYUP() => $process_keys, |
79 | SDL_KEYDOWN() => $process_keys, |
80 | SDL_QUIT() => sub { $done = 1; }, |
81 | ); |
82 | |
83 | while (!$done && $event->wait()) |
84 | { |
85 | if ( $events{$event->type()}) { |
86 | &{$events{$event->type()}}($$event); |
87 | } |
88 | }; |
89 | |