Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ingame
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
ingame
Commits
90ac8836
Commit
90ac8836
authored
Aug 12, 2024
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added hotplug
parent
891da8b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
10 deletions
+23
-10
Gamepad.py
ingame/models/Gamepad.py
+23
-10
No files found.
ingame/models/Gamepad.py
View file @
90ac8836
import
subprocess
import
threading
import
time
from
typing
import
Union
import
pygame
from
pygame.joystick
import
Joystick
class
Gamepad
:
LB_BUTTON
=
4
RB_BUTTON
=
5
...
...
@@ -44,15 +44,28 @@ class Gamepad:
pygame
.
joystick
.
init
()
def
run
(
self
):
joystick_count
=
pygame
.
joystick
.
get_count
()
if
joystick_count
==
0
:
print
(
"No joysticks found."
)
else
:
self
.
joystick
=
pygame
.
joystick
.
Joystick
(
0
)
self
.
joystick
.
init
()
self
.
thread
=
threading
.
Thread
(
target
=
lambda
t
,
_exec
:
t
.
cycle
(),
args
=
(
self
,
exec
))
self
.
thread
.
start
()
def
hotplug
():
joystick_init
=
0
while
True
:
joystick_count
=
pygame
.
joystick
.
get_count
()
if
joystick_count
==
0
:
print
(
"No joysticks found."
)
joystick_init
=
0
pygame
.
event
.
wait
()
time
.
sleep
(
1
)
else
:
if
joystick_init
!=
1
:
self
.
joystick
=
pygame
.
joystick
.
Joystick
(
0
)
self
.
joystick
.
init
()
self
.
thread
=
threading
.
Thread
(
target
=
lambda
t
,
_exec
:
t
.
cycle
(),
args
=
(
self
,
exec
))
self
.
thread
.
start
()
joystick_init
=
1
if
joystick_init
==
1
:
time
.
sleep
(
5
)
hotplug
=
threading
.
Thread
(
name
=
'hotplug'
,
target
=
hotplug
)
hotplug
.
start
()
def
cycle
(
self
):
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment