| 1 | package SDL2::keyboard 0.01 { | ||
| 2 | use SDL2::Utils; | ||
| 3 | use experimental 'signatures'; | ||
| 4 | # | ||
| 5 | use SDL2::stdinc; | ||
| 6 | use SDL2::error; | ||
| 7 | use SDL2::keycode; | ||
| 8 | use SDL2::video; | ||
| 9 | # | ||
| 10 | package SDL2::Keysym { | ||
| 11 | use SDL2::Utils; | ||
| 12 | has | ||
| 13 | scancode => 'SDL_Scancode', | ||
| 14 | sym => 'SDL_Keycode', | ||
| 15 | mod => 'uint16', | ||
| 16 | unused => 'uint32'; | ||
| 17 | }; | ||
| 18 | # | ||
| 19 | attach keyboard => { | ||
| 20 | SDL_GetKeyboardFocus => [ [], 'SDL_Window' ], | ||
| 21 | SDL_GetKeyboardState => [ # Make this nicer for returning lists | ||
| 22 | ['int*'], | ||
| 23 | 'uint8[' . SDL2::FFI::SDL_NUM_SCANCODES() . ']' => sub ( $inner, $numkeys = () ) { | ||
| 24 | my $retval = $inner->($numkeys); | ||
| 25 | wantarray ? @$retval : $retval; | ||
| 26 | } | ||
| 27 | ], | ||
| 28 | SDL_GetModState => [ [], 'SDL_Keymod' ], | ||
| 29 | SDL_SetModState => [ ['SDL_Keymod'] ], | ||
| 30 | SDL_GetKeyFromScancode => [ ['SDL_Scancode'], 'SDL_Keycode' ], | ||
| 31 | SDL_GetScancodeFromKey => [ ['SDL_Keycode'], 'SDL_Scancode' ], | ||
| 32 | SDL_GetScancodeName => [ ['SDL_Scancode'], 'string' ], | ||
| 33 | SDL_GetScancodeFromName => [ ['string'], 'SDL_Scancode' ], | ||
| 34 | SDL_GetKeyName => [ ['SDL_Keycode'], 'string' ], | ||
| 35 | SDL_GetKeyFromName => [ ['string'], 'SDL_Keycode' ], | ||
| 36 | SDL_StartTextInput => [ [] ], | ||
| 37 | SDL_IsTextInputActive => [ [], 'SDL_bool' ], | ||
| 38 | SDL_StopTextInput => [ [] ], | ||
| 39 | SDL_SetTextInputRect => [ ['SDL_Rect'] ], | ||
| 40 | SDL_HasScreenKeyboardSupport => [ [], 'SDL_bool' ], | ||
| 41 | SDL_IsScreenKeyboardShown => [ ['SDL_Window'], 'SDL_bool' ] | ||
| 42 | }; | ||
| 43 | |||
| 44 | =encoding utf-8 | ||
| 45 | |||
| 46 | =head1 NAME | ||
| 47 | |||
| 48 | SDL2::keyboard - SDL Keyboard Event Handling | ||
| 49 | |||
| 50 | =head1 SYNOPSIS | ||
| 51 | |||
| 52 | use SDL2 qw[:keyboard]; | ||
| 53 | |||
| 54 | =head1 DESCRIPTION | ||
| 55 | |||
| 56 | SDL2::keyboard | ||
| 57 | |||
| 58 | =head1 Functions | ||
| 59 | |||
| 60 | =head2 C<SDL_GetKeyboardFocus( )> | ||
| 61 | |||
| 62 | Query the window which currently has keyboard focus. | ||
| 63 | |||
| 64 | Returns the window with keyboard focus. | ||
| 65 | |||
| 66 | =head2 C<SDL_GetKeyboardState( ... )> | ||
| 67 | |||
| 68 | Get a snapshot of the current state of the keyboard. | ||
| 69 | |||
| 70 | my @state = SDL_GetKeyboardState(undef); | ||
| 71 | if ( $state[SDL_SCANCODE_RETURN] ) { | ||
| 72 | printf("<RETURN> is pressed.\n"); | ||
| 73 | } | ||
| 74 | elsif ( $state[SDL_SCANCODE_RIGHT] && $state[SDL_SCANCODE_UP] ) { | ||
| 75 | printf("Right and Up Keys Pressed.\n"); | ||
| 76 | } | ||
| 77 | |||
| 78 | A array element with a value of C<1> means that the key is pressed and a value | ||
| 79 | of C<0> means that it is not. Indexes into this array are obtained by using L<< | ||
| 80 | C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> values. | ||
| 81 | |||
| 82 | Use C<SDL_PumpEvents( )> to update the state array. | ||
| 83 | |||
| 84 | This function gives you the current state after all events have been processed, | ||
| 85 | so if a key or button has been pressed and released before you process events, | ||
| 86 | then the pressed state will never show up in the C<SDL_GetKeyboardState( )> | ||
| 87 | calls. | ||
| 88 | |||
| 89 | Note: This function doesn't take into account whether shift has been pressed or | ||
| 90 | not. | ||
| 91 | |||
| 92 | Expected parameters include: | ||
| 93 | |||
| 94 | =over | ||
| 95 | |||
| 96 | =item C<numkeys> - if non-NULL, receives the length of the returned array | ||
| 97 | |||
| 98 | =back | ||
| 99 | |||
| 100 | Returns a pointer to an array of key states. | ||
| 101 | |||
| 102 | =head2 C<SDL_GetModState( )> | ||
| 103 | |||
| 104 | Get the current key modifier state for the keyboard. | ||
| 105 | |||
| 106 | Returns an OR'd combination of the modifier keys for the keyboard. See L<< | ||
| 107 | C<SDL_Keymod>|SDL2::keycode/C<SDL_Keymod> >> for details. | ||
| 108 | |||
| 109 | =head2 C<SDL_SetModState( ... )> | ||
| 110 | |||
| 111 | Set the current key modifier state for the keyboard. | ||
| 112 | |||
| 113 | The inverse of L<< C<SDL_GetModState( )>|/C<SDL_GetModState( )> >>, | ||
| 114 | C<SDL_SetModState( ... )> allows you to impose modifier key states on your | ||
| 115 | application. Simply pass your desired modifier states into C<modstate>. This | ||
| 116 | value may be a bitwise, OR'd combination of L<< | ||
| 117 | C<SDL_Keymod>|SDL2::keycode/C<SDL_Keymod> >> values. | ||
| 118 | |||
| 119 | This does not change the keyboard state, only the key modifier flags that SDL | ||
| 120 | reports. | ||
| 121 | |||
| 122 | Expected parameters include: | ||
| 123 | |||
| 124 | =over | ||
| 125 | |||
| 126 | =item C<modstate> - the desired L<< C<SDL_Keymod>|SDL2::keycode/C<SDL_Keymod> >> for the keyboard | ||
| 127 | |||
| 128 | =back | ||
| 129 | |||
| 130 | =head2 C<SDL_GetKeyFromScancode( ... )> | ||
| 131 | |||
| 132 | Get the key code corresponding to the given scancode according to the current | ||
| 133 | keyboard layout. | ||
| 134 | |||
| 135 | See L<< C<SDL_Keycode>|SDL2::keycode/C<SDL_Keycode> >> for details. | ||
| 136 | |||
| 137 | Expected parameters include: | ||
| 138 | |||
| 139 | =over | ||
| 140 | |||
| 141 | =item C<scancode> - the desired L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> to query | ||
| 142 | |||
| 143 | =back | ||
| 144 | |||
| 145 | Returns the L<< C<SDL_Keycode>|SDL2::keycode/C<SDL_Keycode> >> that corresponds | ||
| 146 | to the given L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >>. | ||
| 147 | |||
| 148 | =head2 C<SDL_GetScancodeFromKey( ... )> | ||
| 149 | |||
| 150 | Get the scancode corresponding to the given key code according to the current | ||
| 151 | keyboard layout. | ||
| 152 | |||
| 153 | See L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> for details. | ||
| 154 | |||
| 155 | Expected parameters include: | ||
| 156 | |||
| 157 | =over | ||
| 158 | |||
| 159 | =item C<key> - the desired L<< C<SDL_Keycode>|SDL2::keycode/C<SDL_Keycode> >> to query | ||
| 160 | |||
| 161 | =back | ||
| 162 | |||
| 163 | Returns the L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> that | ||
| 164 | corresponds to the given L<< C<SDL_Keycode>|SDL2::keycode/C<SDL_Keycode> >>. | ||
| 165 | |||
| 166 | =head2 C<SDL_GetScancodeName( ... )> | ||
| 167 | |||
| 168 | Get a human-readable name for a scancode. | ||
| 169 | |||
| 170 | See L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> for details. | ||
| 171 | |||
| 172 | B<Warning>: The returned name is by design not stable across platforms, e.g. | ||
| 173 | the name for C<SDL_SCANCODE_LGUI> is "Left GUI" under Linux but "Left Windows" | ||
| 174 | under Microsoft Windows, and some scancodes like C<SDL_SCANCODE_NONUSBACKSLASH> | ||
| 175 | don't have any name at all. There are even scancodes that share names, e.g. | ||
| 176 | C<SDL_SCANCODE_RETURN> and C<SDL_SCANCODE_RETURN2> (both called "Return"). This | ||
| 177 | function is therefore unsuitable for creating a stable cross-platform two-way | ||
| 178 | mapping between strings and scancodes. | ||
| 179 | |||
| 180 | Expected parameters include: | ||
| 181 | |||
| 182 | =over | ||
| 183 | |||
| 184 | =item C<scancode> the desired L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> to query | ||
| 185 | |||
| 186 | =back | ||
| 187 | |||
| 188 | Returns the name for the scancode. If the scancode doesn't have a name this | ||
| 189 | function returns an empty string (C<"">). | ||
| 190 | |||
| 191 | =head2 C<SDL_GetScancodeFromName( ... )> | ||
| 192 | |||
| 193 | Get a scancode from a human-readable name. | ||
| 194 | |||
| 195 | Expected parameters include: | ||
| 196 | |||
| 197 | =over | ||
| 198 | |||
| 199 | =item C<name> - the human-readable scancode name | ||
| 200 | |||
| 201 | =back | ||
| 202 | |||
| 203 | Returns the L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> , or | ||
| 204 | C<SDL_SCANCODE_UNKNOWN> if the name wasn't recognized; call C<SDL_GetError( )> | ||
| 205 | for more information. | ||
| 206 | |||
| 207 | =head2 C<SDL_GetKeyName( ... )> | ||
| 208 | |||
| 209 | Get a human-readable name for a key. | ||
| 210 | |||
| 211 | See L<< C<SDL_Scancode>|SDL2::scancode/C<SDL_Scancode> >> and L<< | ||
| 212 | C<SDL_Keycode>|SDL2::keycode/C<SDL_Keycode> >> for details. | ||
| 213 | |||
| 214 | Expected parameters include: | ||
| 215 | |||
| 216 | =over | ||
| 217 | |||
| 218 | =item C<key> - the desired SDL_Keycode to query | ||
| 219 | |||
| 220 | =back | ||
| 221 | |||
| 222 | Returns a pointer to a UTF-8 string that stays valid at least until the next | ||
| 223 | call to this function. If you need it around any longer, you must copy it. If | ||
| 224 | the key doesn't have a name, this function returns an empty string (C<"">). | ||
| 225 | |||
| 226 | =head2 C<SDL_GetKeyFromName( ... )> | ||
| 227 | |||
| 228 | Get a key code from a human-readable name. | ||
| 229 | |||
| 230 | Expected parameters include: | ||
| 231 | |||
| 232 | =over | ||
| 233 | |||
| 234 | =item C<name> - the human-readable key name | ||
| 235 | |||
| 236 | =back | ||
| 237 | |||
| 238 | Returns key code, or C<SDLK_UNKNOWN> if the name wasn't recognized; call | ||
| 239 | C<SDL_GetError( )> for more information. | ||
| 240 | |||
| 241 | =head2 C<SDL_StartTextInput( )> | ||
| 242 | |||
| 243 | Start accepting Unicode text input events. | ||
| 244 | |||
| 245 | This function will start accepting Unicode text input events in the focused SDL | ||
| 246 | window, and start emitting C<SDL_TextInputEvent> (C<SDL_TEXTINPUT>) and | ||
| 247 | C<SDL_TextEditingEvent> (C<SDL_TEXTEDITING>) events. Please use this function | ||
| 248 | in pair with L<< C<SDL_StopTextInput( )>|/C<SDL_StopTextInput( )> >>. | ||
| 249 | |||
| 250 | On some platforms using this function activates the screen keyboard. | ||
| 251 | |||
| 252 | =head2 C<SDL_IsTextInputActive( )> | ||
| 253 | |||
| 254 | Check whether or not Unicode text input events are enabled. | ||
| 255 | |||
| 256 | Returns C<SDL_TRUE> if text input events are enabled else C<SDL_FALSE>. | ||
| 257 | |||
| 258 | =head2 C<SDL_StopTextInput( )> | ||
| 259 | |||
| 260 | Stop receiving any text input events. | ||
| 261 | |||
| 262 | =head2 C<SDL_SetTextInputRect( )> | ||
| 263 | |||
| 264 | Set the rectangle used to type Unicode text inputs. | ||
| 265 | |||
| 266 | Expected parameters include: | ||
| 267 | |||
| 268 | =over | ||
| 269 | |||
| 270 | =item C<rect> - the L<SDL2::Rect> structure representing the rectangle to receive text (ignored if C<undef>) | ||
| 271 | |||
| 272 | =back | ||
| 273 | |||
| 274 | =head2 C<SDL_HasScreenKeyboardSupport( )> | ||
| 275 | |||
| 276 | Check whether the platform has screen keyboard support. | ||
| 277 | |||
| 278 | Returns C<SDL_TRUE> if the platform has some screen keyboard support or | ||
| 279 | C<SDL_FALSE> if not. | ||
| 280 | |||
| 281 | =head2 C<SDL_IsScreenKeyboardShown( ... )> | ||
| 282 | |||
| 283 | Check whether the screen keyboard is shown for given window. | ||
| 284 | |||
| 285 | Expected parameters include: | ||
| 286 | |||
| 287 | =over | ||
| 288 | |||
| 289 | =item C<window> - the window for which screen keyboard should be queried | ||
| 290 | |||
| 291 | =back | ||
| 292 | |||
| 293 | Returns C<SDL_TRUE> if screen keyboard is shown or C<SDL_FALSE> if not. | ||
| 294 | |||
| 295 | =head1 LICENSE | ||
| 296 | |||
| 297 | Copyright (C) Sanko Robinson. | ||
| 298 | |||
| 299 | This library is free software; you can redistribute it and/or modify it under | ||
| 300 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||
| 301 | conditions may apply to data transmitted through this module. | ||
| 302 | |||
| 303 | =head1 AUTHOR | ||
| 304 | |||
| 305 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||
| 306 | |||
| 307 | =begin stopwords | ||
| 308 | |||
| 309 | bitwise scancodes scancode | ||
| 310 | |||
| 311 | =end stopwords | ||
| 312 | |||
| 313 | =cut | ||
| 314 | |||
| 315 | }; | ||
| 316 | 1; |