How to override CTRL+Y in a python script?
Asked Answered
S

1

6

I want to implement Ctrl+Y as a hotkey in my python script, however, Ctrl+Y will cause a signal to be sent to my script, causing it to stop.

How can I override the Ctrl+Y key combination within the python script?

I have tried:

import signal
signal.signal(signal.SIGSTOP, signal.SIG_IGN)

but this will cause RunTimeError (22, 'invalid argument').

Sesquicentennial answered 18/10, 2015 at 10:58 Comment(1)
Whether or not CTRL+Y sends a signal to your script is terminal-dependent (and configurable from the terminal).Amorist
P
0

The problem with your code is that you are trying to interrupt SIGSTOP which is uninterruptible. You want to interrupt SIGTSTP like so:

import signal
signal.signal(signal.SIGTSTP, signal.SIG_IGN)
Polynesian answered 3/2, 2020 at 17:29 Comment(1)
That prevents ^Y from stopping the program, but the key still doesn't get transmitted, it's just ignored now.Miyamoto

© 2022 - 2024 — McMap. All rights reserved.