K
K
Kryptonit2021-11-16 22:35:57
Python
Kryptonit, 2021-11-16 22:35:57

How to stop entering values ​​on pressing CTRL?

import keyboard
Array = []
while not(keyboard.is_pressed('ctrl')):
    Array += input()
print(Array)

I want the next value to be entered when enter is pressed, but is_pressed always works, except when we use input
, I don’t want to put any value in while, because the task is to get a list of strings.
It is necessary to press the service keys.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-11-17
@Kryptonit

import signal
import time


class SigHandler:
    stop = False

    def __init__(self):
        signal.signal(signal.SIGINT, self.exit)
        signal.signal(signal.SIGTERM, self.exit)

    def exit(self, *args):
        print(signal.strsignal(args[0]))
        self.stop = True


if __name__ == '__main__':
    Array = []

    signal_handler = SigHandler()
    while not signal_handler.stop:
        Array += input('Input value: ')
        print(Array)
        time.sleep(0.5)

    print("Exit")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question