Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if running from a tty on windows #1657

Merged
merged 1 commit into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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