Sep-24-2020, 12:06 PM
I changed your code a bit.
Does marketloop require access to key events?
If it's the case, code needs to be changed. Again.
Does marketloop require access to key events?
If it's the case, code needs to be changed. Again.
import pyautogui as pg import time import keyboard import random import win32api, win32con import threading from pynput.mouse import Button, Controller from pynput.keyboard import Listener, KeyCode class BuffItems(threading.Thread): def __init__(self): super().__init__() self.running = False self.pause = False def start(self): """ Duplicates the start method of threading.Thread """ if not self.running: self.running = True super().start() def stop(self): self.running = False def pause_toggle(self): self.pause = not self.pause def run(self): while self.running: time.sleep(0.5) # to reduce speed if not self.pause: marketloop() class KeyboardControl: start_stop_key = KeyCode(char='s') exit_key = KeyCode(char='q') def __init__(self): self.listener = Listener(on_press=self.on_press) self.listener.start() self.buff_thread = BuffItems() self.buff_thread.start() def __enter__(self): return self def __exit__(self, *args): self.buff_thread.stop() self.listener.stop() def on_press(self, key): if key == self.start_stop_key and self.buff_thread.running: self.buff_thread.pause_toggle() elif key == self.exit_key and self.buff_thread.running: self.buff_thread.stop() self.listener.stop() def join(self): while self.buff_thread.running: time.sleep(0.1) def marketloop(): print(time.time()) def main(): try: with KeyboardControl() as control: control.join() except KeyboardInterrupt: print("\nReceived SIGINT. Exitting programm.") if __name__ == "__main__": main()
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!