Skip to content

Commit

Permalink
Enable windowed mode and raw input to get all inputs on virtual display
Browse files Browse the repository at this point in the history
This fixes an issue where the game does not receive most of the inputs
sent to the virtual display. It is not really clear why this change is
necessary, something related to the game or the X server must have
changed recently...

Note: Fixed some formatting along the way.
  • Loading branch information
iksnagreb committed Apr 28, 2022
1 parent 3a9d37b commit 755612e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gym_csgo/glue/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# Sets keyboard key state
def set_key( controller, key, state ):
def set_key(controller, key, state):
# If state is True (Pressed)
if state:
# Press the key
Expand All @@ -14,7 +14,7 @@ def set_key( controller, key, state ):


# Sets Counter Strike: Global Offensive keyboard key state
def control_keyboard( controller, state ):
def control_keyboard(controller, state):
# Set move forward state
set_key(controller, 'W', state['forward'])
# Set move left state
Expand Down Expand Up @@ -45,7 +45,7 @@ def control_keyboard( controller, state ):


# Resets Counter Strike: Global Offensive keyboard key state
def reset_keyboard( controller ):
def reset_keyboard(controller):
# Set move forward state
set_key(controller, 'W', False)
# Set move left state
Expand Down
9 changes: 6 additions & 3 deletions gym_csgo/glue/mouse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Pynput library to interact with the mouse
from pynput import mouse


# Sets mouse button state
def set_button( controller, button, state ):
def set_button(controller, button, state):
# If state is True (Pressed)
if state:
# Press the mouse button
Expand All @@ -11,17 +12,19 @@ def set_button( controller, button, state ):
# Otherwise release the mouse button
controller.release(button)


# Sets Counter Strike: Global Offensive mouse state
def control_mouse( controller, state ):
def control_mouse(controller, state):
# Set special state
set_button(controller, mouse.Button.right, state['special'])
# Set fire state
set_button(controller, mouse.Button.left, state['fire'])
# Move the mouse pointer (moves the game camera)
controller.move(*state['camera'])


# Resets Counter Strike: Global Offensive mouse state
def reset_mouse( controller ):
def reset_mouse(controller):
# Set special state
set_button(controller, mouse.Button.right, False)
# Set fire state
Expand Down
8 changes: 7 additions & 1 deletion gym_csgo/specs/args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Essential startup arguments
ESSENTIAL_ARGS = (
'-insecure', '-untrusted', '-novid', '-nojoy', '+cl_use_opens_buy_menu', '0'
'-insecure',
'-untrusted',
'-novid',
'-nojoy',
'-windowed', '-noborder',
'+cl_use_opens_buy_menu', '0',
'+m_rawinput', '1'
)

0 comments on commit 755612e

Please sign in to comment.