so I recently learned a bit of Python, to make a long story short I made a simple auto strafe script using the keyboard module I will paste the code below, the code seems to work correctly when testing on Notepad and other applications,
If a key is pressed down (KEY_DOWN event), it’s added to the pressed_keys set.
If a key is released (KEY_UP event), and the key was in the pressed_keys set, it is removed from the set, and the press_opposing_key function is called with the released key. so when the script is ran in-game a key is pressed (A) the corresponding key in this case (D) the D key is released but the game forces me in that direction, even when the script is stopped the game continues to force me to go in said direction alt-tabbing seems to stop this, I would just like some help getting around this, I don’t know a lot about anti-cheat or if the anti-cheat has anything to do with this, maybe my code just sucks (It does)
If a key is pressed down (KEY_DOWN event), it’s added to the pressed_keys set.
If a key is released (KEY_UP event), and the key was in the pressed_keys set, it is removed from the set, and the press_opposing_key function is called with the released key. so when the script is ran in-game a key is pressed (A) the corresponding key in this case (D) the D key is released but the game forces me in that direction, even when the script is stopped the game continues to force me to go in said direction alt-tabbing seems to stop this, I would just like some help getting around this, I don’t know a lot about anti-cheat or if the anti-cheat has anything to do with this, maybe my code just sucks (It does)
import pyautogui
import keyboard as key
pressed_keys = set()
def autostrafe(key_event):
key_pressed = key_event.name
if key_event.event_type == key.KEY_DOWN:
pressed_keys.add(key_pressed)
elif key_event.event_type == key.KEY_UP:
if key_pressed in pressed_keys:
pressed_keys.remove(key_pressed)
press_opposing_key(key_pressed)
def press_opposing_key(key_pressed):
key_mapping = {‘a’: ‘d’, ‘d’: ‘a’, ‘w’: ‘s’, ‘s’: ‘w’}
opposing_key = key_mapping.get(key_pressed)
if opposing_key:
key.press(opposing_key)
# Register the autostrafe function for both key down and key up events
key.hook(autostrafe)
# Keep the program running
key.wait(‘7’) # Wait until the ‘7’ key is pressed to exit