Skip to content

Commit

Permalink
Merge pull request #1657 from DennisKrone/issue-1654
Browse files Browse the repository at this point in the history
Check if running from a tty on windows
  • Loading branch information
cyberw authored Dec 11, 2020
2 parents b8aa672 + 4d12718 commit 85d8a44
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions locust/input_events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gevent
import logging
import os
import sys

if os.name == "nt":
from win32api import STD_INPUT_HANDLE
Expand All @@ -12,7 +13,6 @@
ENABLE_PROCESSED_INPUT,
)
else:
import sys
import select
import termios
import tty
Expand Down Expand Up @@ -43,11 +43,14 @@ def poll(_self):

class WindowsKeyPoller:
def __init__(self):
self.read_handle = GetStdHandle(STD_INPUT_HANDLE)
self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
self.cur_event_length = 0
self.cur_keys_length = 0
self.captured_chars = []
if sys.stdin.isatty():
self.read_handle = GetStdHandle(STD_INPUT_HANDLE)
self.read_handle.SetConsoleMode(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_INPUT)
self.cur_event_length = 0
self.cur_keys_length = 0
self.captured_chars = []
else:
raise InitError("Terminal was not a tty. Keyboard input disabled")

def cleanup(self):
pass
Expand Down

0 comments on commit 85d8a44

Please sign in to comment.