1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>pygame._sdl2.controller — pygame v2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="shortcut icon" href="../_static/pygame.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="pygame.sdl2_video" href="sdl2_video.html" />
<link rel="prev" title="pygame.scrap" href="scrap.html" />
</head><body>
<div class="document">
<div class="header">
<table>
<tr>
<td class="logo">
<a href="https://www.pygame.org/">
<img src="../_static/pygame_tiny.png"/>
</a>
<h5>pygame documentation</h5>
</td>
<td class="pagelinks">
<div class="top">
<a href="https://www.pygame.org/">Pygame Home</a> ||
<a href="../index.html">Help Contents</a> ||
<a href="../genindex.html">Reference Index</a>
<form action="../search.html" method="get" style="display:inline;float:right;">
<input name="q" value="" type="text">
<input value="search" type="submit">
</form>
</div>
<hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
<p class="bottom"><b>Most useful stuff</b>:
<a href="color.html">Color</a> |
<a href="display.html">display</a> |
<a href="draw.html">draw</a> |
<a href="event.html">event</a> |
<a href="font.html">font</a> |
<a href="image.html">image</a> |
<a href="key.html">key</a> |
<a href="locals.html">locals</a> |
<a href="mixer.html">mixer</a> |
<a href="mouse.html">mouse</a> |
<a href="rect.html">Rect</a> |
<a href="surface.html">Surface</a> |
<a href="time.html">time</a> |
<a href="music.html">music</a> |
<a href="pygame.html">pygame</a>
</p>
<p class="bottom"><b>Advanced stuff</b>:
<a href="cursors.html">cursors</a> |
<a href="joystick.html">joystick</a> |
<a href="mask.html">mask</a> |
<a href="sprite.html">sprite</a> |
<a href="transform.html">transform</a> |
<a href="bufferproxy.html">BufferProxy</a> |
<a href="freetype.html">freetype</a> |
<a href="gfxdraw.html">gfxdraw</a> |
<a href="midi.html">midi</a> |
<a href="pixelarray.html">PixelArray</a> |
<a href="pixelcopy.html">pixelcopy</a> |
<a href="sndarray.html">sndarray</a> |
<a href="surfarray.html">surfarray</a> |
<a href="math.html">math</a>
</p>
<p class="bottom"><b>Other</b>:
<a href="camera.html">camera</a> |
<a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> |
<a href="examples.html">examples</a> |
<a href="fastevent.html">fastevent</a> |
<a href="scrap.html">scrap</a> |
<a href="tests.html">tests</a> |
<a href="touch.html">touch</a> |
<a href="pygame.html#module-pygame.version">version</a>
</p>
</td>
</tr>
</table>
</div>
<div class="documentwrapper">
<div class="body" role="main">
<section id="module-pygame._sdl2.controller">
<span id="pygame-sdl2-controller"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame._sdl2.controller</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Pygame module to work with controllers.</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 32%" />
<col style="width: 1%" />
<col style="width: 67%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.init">pygame._sdl2.controller.init</a></div>
</td>
<td>—</td>
<td>initialize the controller module</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.quit">pygame._sdl2.controller.quit</a></div>
</td>
<td>—</td>
<td>Uninitialize the controller module.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.get_init">pygame._sdl2.controller.get_init</a></div>
</td>
<td>—</td>
<td>Returns True if the controller module is initialized.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.set_eventstate">pygame._sdl2.controller.set_eventstate</a></div>
</td>
<td>—</td>
<td>Sets the current state of events related to controllers</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.get_eventstate">pygame._sdl2.controller.get_eventstate</a></div>
</td>
<td>—</td>
<td>Gets the current state of events related to controllers</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.get_count">pygame._sdl2.controller.get_count</a></div>
</td>
<td>—</td>
<td>Get the number of joysticks connected</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.is_controller">pygame._sdl2.controller.is_controller</a></div>
</td>
<td>—</td>
<td>Check if the given joystick is supported by the game controller interface</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.name_forindex">pygame._sdl2.controller.name_forindex</a></div>
</td>
<td>—</td>
<td>Get the name of the contoller</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller">pygame._sdl2.controller.Controller</a></div>
</td>
<td>—</td>
<td>Create a new Controller object.</td>
</tr>
</tbody>
</table>
<p>This module offers control over common controller types like the dualshock 4 or
the xbox 360 controllers: They have two analog sticks, two triggers, two shoulder buttons,
a dpad, 4 buttons on the side, 2 (or 3) buttons in the middle.</p>
<p>Pygame uses xbox controllers naming conventions (like a, b, x, y for buttons) but
they always refer to the same buttons. For example <code class="docutils literal notranslate"><span class="pre">CONTROLLER_BUTTON_X</span></code> is
always the leftmost button of the 4 buttons on the right.</p>
<p>Controllers can generate the following events:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CONTROLLERAXISMOTION</span><span class="p">,</span> <span class="n">CONTROLLERBUTTONDOWN</span><span class="p">,</span> <span class="n">CONTROLLERBUTTONUP</span><span class="p">,</span>
<span class="n">CONTROLLERDEVICEREMAPPED</span><span class="p">,</span> <span class="n">CONTROLLERDEVICEADDED</span><span class="p">,</span> <span class="n">CONTROLLERDEVICEREMOVED</span>
</pre></div>
</div>
<p>Additionally if pygame is built with SDL 2.0.14 or higher the following events can also be generated
(to get the version of sdl pygame is built with use <a class="tooltip reference internal" href="pygame.html#pygame.version.SDL" title=""><code class="xref py py-meth docutils literal notranslate"><span class="pre">pygame.version.SDL()</span></code><span class="tooltip-content">tupled integers of the SDL library version</span></a>):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CONTROLLERTOUCHPADDOWN</span><span class="p">,</span> <span class="n">CONTROLLERTOUCHPADMOTION</span><span class="p">,</span> <span class="n">CONTROLLERTOUCHPADUP</span>
</pre></div>
</div>
<p>These events can be enabled/disabled by <a class="tooltip reference internal" href="#pygame._sdl2.controller.set_eventstate" title=""><code class="xref py py-meth docutils literal notranslate"><span class="pre">pygame._sdl2.controller.set_eventstate()</span></code><span class="tooltip-content">Sets the current state of events related to controllers</span></a>
Note that controllers can generate joystick events as well. This function only toggles
events related to controllers.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>See the <a class="tooltip reference internal" href="joystick.html#module-pygame.joystick" title=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.joystick</span></code><span class="tooltip-content">Pygame module for interacting with joysticks, gamepads, and trackballs.</span></a> for a more versatile but more advanced api.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2: </span>This module requires SDL2.</p>
</div>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.init">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">init</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.init" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">initialize the controller module</span></div>
<div class="line"><span class="signature">init() -> None</span></div>
</div>
<p>Initialize the controller module.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.quit">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.quit" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Uninitialize the controller module.</span></div>
<div class="line"><span class="signature">quit() -> None</span></div>
</div>
<p>Uninitialize the controller module.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.get_init">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">get_init</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.get_init" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Returns True if the controller module is initialized.</span></div>
<div class="line"><span class="signature">get_init() -> bool</span></div>
</div>
<p>Test if <code class="docutils literal notranslate"><span class="pre">pygame._sdl2.controller.init()</span></code> was called.</p>
<blockquote>
<div></div></blockquote>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.set_eventstate">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">set_eventstate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.set_eventstate" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Sets the current state of events related to controllers</span></div>
<div class="line"><span class="signature">set_eventstate(state) -> None</span></div>
</div>
<p>Enable or disable events connected to controllers.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Controllers can still generate joystick events, which will not be toggled by this function.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.2:: </span>Changed return type from int to None</p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.get_eventstate">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">get_eventstate</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.get_eventstate" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Gets the current state of events related to controllers</span></div>
<div class="line"><span class="signature">get_eventstate() -> bool</span></div>
</div>
<p>Returns the current state of events related to controllers, True meaning
events will be posted.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.2.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.get_count">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">get_count</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.get_count" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Get the number of joysticks connected</span></div>
<div class="line"><span class="signature">get_count() -> int</span></div>
</div>
<p>Get the number of joysticks connected.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.is_controller">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">is_controller</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.is_controller" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Check if the given joystick is supported by the game controller interface</span></div>
<div class="line"><span class="signature">is_controller(index) -> bool</span></div>
</div>
<p>Returns True if the index given can be used to create a controller object.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.name_forindex">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">name_forindex</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.name_forindex" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Get the name of the contoller</span></div>
<div class="line"><span class="signature">name_forindex(index) -> name or None</span></div>
</div>
<p>Returns the name of controller, or None if there's no name or the
index is invalid.</p>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller">
<span class="sig-prename descclassname"><span class="pre">pygame._sdl2.controller.</span></span><span class="sig-name descname"><span class="pre">Controller</span></span><a class="headerlink" href="#pygame._sdl2.controller.Controller" title="Permalink to this definition">¶</a></dt>
<dd><blockquote>
<div><div class="line-block">
<div class="line"><span class="summaryline">Create a new Controller object.</span></div>
<div class="line"><span class="signature">Controller(index) -> Controller</span></div>
</div>
<p>Create a new Controller object. Index should be integer between
0 and <code class="docutils literal notranslate"><span class="pre">pygame._sdl2.contoller.get_count()</span></code>. Controllers also
can be created from a <code class="docutils literal notranslate"><span class="pre">pygame.joystick.Joystick</span></code> using
<code class="docutils literal notranslate"><span class="pre">pygame._sdl2.controller.from_joystick</span></code>. Controllers are
initialized on creation.</p>
</div></blockquote>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 39%" />
<col style="width: 1%" />
<col style="width: 60%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.quit">pygame._sdl2.controller.Controller.quit</a></div>
</td>
<td>—</td>
<td>uninitialize the Controller</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.get_init">pygame._sdl2.controller.Controller.get_init</a></div>
</td>
<td>—</td>
<td>check if the Controller is initialized</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.from_joystick">pygame._sdl2.controller.Controller.from_joystick</a></div>
</td>
<td>—</td>
<td>Create a Controller from a pygame.joystick.Joystick object</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.attached">pygame._sdl2.controller.Controller.attached</a></div>
</td>
<td>—</td>
<td>Check if the Controller has been opened and is currently connected.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.as_joystick">pygame._sdl2.controller.Controller.as_joystick</a></div>
</td>
<td>—</td>
<td>Returns a pygame.joystick.Joystick() object</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.get_axis">pygame._sdl2.controller.Controller.get_axis</a></div>
</td>
<td>—</td>
<td>Get the current state of a joystick axis</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.get_button">pygame._sdl2.controller.Controller.get_button</a></div>
</td>
<td>—</td>
<td>Get the current state of a button</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.get_mapping">pygame._sdl2.controller.Controller.get_mapping</a></div>
</td>
<td>—</td>
<td>Get the mapping assigned to the controller</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.set_mapping">pygame._sdl2.controller.Controller.set_mapping</a></div>
</td>
<td>—</td>
<td>Assign a mapping to the controller</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.rumble">pygame._sdl2.controller.Controller.rumble</a></div>
</td>
<td>—</td>
<td>Start a rumbling effect</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sdl2_controller.html#pygame._sdl2.controller.Controller.stop_rumble">pygame._sdl2.controller.Controller.stop_rumble</a></div>
</td>
<td>—</td>
<td>Stop any rumble effect playing</td>
</tr>
</tbody>
</table>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.quit">
<span class="sig-name descname"><span class="pre">quit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.quit" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">uninitialize the Controller</span></div>
<div class="line"><span class="signature">quit() -> None</span></div>
</div>
<p>Close a Controller object. After this the pygame event queue will no longer
receive events from the device.</p>
<p>It is safe to call this more than once.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.get_init">
<span class="sig-name descname"><span class="pre">get_init</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.get_init" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">check if the Controller is initialized</span></div>
<div class="line"><span class="signature">get_init() -> bool</span></div>
</div>
<p>Returns True if the Controller object is currently initialised.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.from_joystick">
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">from_joystick</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.from_joystick" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Create a Controller from a pygame.joystick.Joystick object</span></div>
<div class="line"><span class="signature">from_joystick(joystick) -> Controller</span></div>
</div>
<p>Create a Controller object from a <code class="docutils literal notranslate"><span class="pre">pygame.joystick.Joystick</span></code> object</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.attached">
<span class="sig-name descname"><span class="pre">attached</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.attached" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Check if the Controller has been opened and is currently connected.</span></div>
<div class="line"><span class="signature">attached() -> bool</span></div>
</div>
<p>Returns True if the Controller object is opened and connected.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.as_joystick">
<span class="sig-name descname"><span class="pre">as_joystick</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.as_joystick" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Returns a pygame.joystick.Joystick() object</span></div>
<div class="line"><span class="signature">as_joystick() -> Joystick object</span></div>
</div>
<p>Returns a pygame.joystick.Joystick() object created from this controller's index</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.get_axis">
<span class="sig-name descname"><span class="pre">get_axis</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.get_axis" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Get the current state of a joystick axis</span></div>
<div class="line"><span class="signature">get_axis(axis) -> int</span></div>
</div>
<p>Get the current state of a trigger or joystick axis.
The axis argument must be one of the following constants:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CONTROLLER_AXIS_LEFTX</span><span class="p">,</span> <span class="n">CONTROLLER_AXIS_LEFTY</span><span class="p">,</span>
<span class="n">CONTROLLER_AXIS_RIGHTX</span><span class="p">,</span> <span class="n">CONTROLLER_AXIS_RIGHTY</span><span class="p">,</span>
<span class="n">CONTROLLER_AXIS_TRIGGERLEFT</span><span class="p">,</span> <span class="n">CONTROLLER_AXIS_TRIGGERRIGHT</span>
</pre></div>
</div>
<p>Joysticks can return a value between -32768 and 32767. Triggers however
can only return a value between 0 and 32768.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.get_button">
<span class="sig-name descname"><span class="pre">get_button</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.get_button" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Get the current state of a button</span></div>
<div class="line"><span class="signature">get_button(button) -> bool</span></div>
</div>
<p>Get the current state of a button, True meaning it is pressed down.
The button argument must be one of the following constants:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">CONTROLLER_BUTTON_A</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_B</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_X</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_Y</span>
<span class="n">CONTROLLER_BUTTON_DPAD_UP</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_DPAD_DOWN</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_DPAD_LEFT</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_DPAD_RIGHT</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_LEFTSHOULDER</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_RIGHTSHOULDER</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_LEFTSTICK</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_RIGHTSTICK</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_BACK</span><span class="p">,</span> <span class="n">CONTROLLER_BUTTON_GUIDE</span><span class="p">,</span>
<span class="n">CONTROLLER_BUTTON_START</span>
</pre></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.get_mapping">
<span class="sig-name descname"><span class="pre">get_mapping</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.get_mapping" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Get the mapping assigned to the controller</span></div>
<div class="line"><span class="signature">get_mapping() -> mapping</span></div>
</div>
<p>Returns a dict containing the mapping of the Controller. For more
information see <a class="reference internal" href="#pygame._sdl2.controller.Controller.set_mapping" title="pygame._sdl2.controller.Controller.set_mapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Controller.set_mapping()</span></code></a></p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.2:: </span>Return type changed from <code class="docutils literal notranslate"><span class="pre">str</span></code> to <code class="docutils literal notranslate"><span class="pre">dict</span></code></p>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.set_mapping">
<span class="sig-name descname"><span class="pre">set_mapping</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.set_mapping" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Assign a mapping to the controller</span></div>
<div class="line"><span class="signature">set_mapping(mapping) -> int</span></div>
</div>
<p>Rebind buttons, axes, triggers and dpads. The mapping should be a
dict containing all buttons, hats and axes. The easiest way to get this
is to use the dict returned by <a class="reference internal" href="#pygame._sdl2.controller.Controller.get_mapping" title="pygame._sdl2.controller.Controller.get_mapping"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Controller.get_mapping()</span></code></a>. To edit
this mapping assign a value to the original button. The value of the
dictionary must be a button, hat or axis represented in the following way:</p>
<ul class="simple">
<li><p>For a button use: bX where X is the index of the button.</p></li>
<li><p>For a hat use: hX.Y where X is the index and the Y is the direction (up: 1, right: 2, down: 3, left: 4).</p></li>
<li><p>For an axis use: aX where x is the index of the axis.</p></li>
</ul>
<p>An example of mapping:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mapping</span> <span class="o">=</span> <span class="n">controller</span><span class="o">.</span><span class="n">get_mapping</span><span class="p">()</span> <span class="c1"># Get current mapping</span>
<span class="n">mapping</span><span class="p">[</span><span class="s2">"a"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"b3"</span> <span class="c1"># Remap button a to y</span>
<span class="n">mapping</span><span class="p">[</span><span class="s2">"y"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"b0"</span> <span class="c1"># Remap button y to a</span>
<span class="n">controller</span><span class="o">.</span><span class="n">set_mapping</span><span class="p">(</span><span class="n">mapping</span><span class="p">)</span> <span class="c1"># Set the mapping</span>
</pre></div>
</div>
<p>The function will return 1 if a new mapping is added or 0 if an existing one is updated.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.2:: </span>Renamed from <code class="docutils literal notranslate"><span class="pre">add_mapping</span></code> to <code class="docutils literal notranslate"><span class="pre">set_mapping</span></code></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.2:: </span>Argument type changed from <code class="docutils literal notranslate"><span class="pre">str</span></code> to <code class="docutils literal notranslate"><span class="pre">dict</span></code></p>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.rumble">
<span class="sig-name descname"><span class="pre">rumble</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.rumble" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Start a rumbling effect</span></div>
<div class="line"><span class="signature">rumble(low_frequency, high_frequency, duration) -> bool</span></div>
</div>
<p>Start a rumble effect on the controller, with the specified strength ranging
from 0 to 1. Duration is length of the effect, in ms. Setting the duration
to 0 will play the effect until another one overwrites it or
<a class="reference internal" href="#pygame._sdl2.controller.Controller.stop_rumble" title="pygame._sdl2.controller.Controller.stop_rumble"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Controller.stop_rumble()</span></code></a> is called. If an effect is already
playing, then it will be overwritten.</p>
<p>Returns True if the rumble was played successfully or False if the
controller does not support it or <a class="tooltip reference internal" href="pygame.html#pygame.version.SDL" title=""><code class="xref py py-meth docutils literal notranslate"><span class="pre">pygame.version.SDL()</span></code><span class="tooltip-content">tupled integers of the SDL library version</span></a> is below 2.0.9.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.2.</span></p>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame._sdl2.controller.Controller.stop_rumble">
<span class="sig-name descname"><span class="pre">stop_rumble</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame._sdl2.controller.Controller.stop_rumble" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Stop any rumble effect playing</span></div>
<div class="line"><span class="signature">stop_rumble() -> None</span></div>
</div>
<p>Stops any rumble effect playing on the controller. See
<a class="reference internal" href="#pygame._sdl2.controller.Controller.rumble" title="pygame._sdl2.controller.Controller.rumble"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Controller.rumble()</span></code></a> for more information.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.2.</span></p>
</div>
</dd></dl>
</dd></dl>
</dd></dl>
</section>
<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/sdl2_controller.rst" rel="nofollow">Edit on GitHub</a>
<div class="clearer"></div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="sdl2_video.html" title="pygame.sdl2_video"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="scrap.html" title="pygame.scrap"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame._sdl2.controller</span></code></a></li>
<script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2000-2021, pygame developers.
</div>
</body>
</html>
|