I have a Python app that I have running from an EXE that I created from Python. It does some Windows automation while I work with a bunch of Excel workbooks. Primarily, the Python app “lurks” in the background waiting for Excel to pop up a “Password” box, and the Python app supplies the password. If, while working on a workbook, I press Ctrl-S to save the workbook, the Python app stops working. I found that if I press Ctrl-S AGAIN, the Python app wakes up and functions normally. Is this normal? If so, can I somehow tell Python not to do that?
It’s not normal, and it’s not any feature of Python that could be disabled. What automation library are you using to handle the password box?
Thanks for the reply.
I am a newbie to Python (although I have been programming since the days of wooden disks.)
I am using pywinauto.
Michael R. Frumer
In a command-line context, ctrl-S can mean “scroll lock”. This is traditionally a Unix feature, but I think the Windows command line also implements it.
… and I saw a post someplace that said that Ctrl-S would pause Python output to the terminal and that pressing Ctrl-S again would un-pause it. That was why I tried the second Ctrl-S. It worked, so I can live with it, but it seems weird.
Michael R. Frumer
Ctrl+S (ASCII DC3) can be interpreted by some terminals as XOFF (pause transmission), in which case Ctrl+Q (ASCII DC1) should be interpreted as XON (resume transmission). Pressing Ctrl+S again should have no effect. Even if it did, since Excel has the focus, a terminal window wouldn’t see a keyboard event when Ctrl+S is pressed.
Yes, because Excel had the focus, I was surprised that the Ctrl-S could impact my Python app.
But after I read about the console being paused (which did not seem related) in: https://stackoverflow.com/questions/39041547/in-python-why-does-console-output-occasionally-pause-until-ctrl-c-is-pressed-a
I figured, “Well, it’s worth a shot. I can’t find anything else.”, and I was delighted that a second Ctrl-S woke the app up again.
So far, with this initial foray into Python, it is just a minor inconvenience, but I thought that further into my use of Windows automation it might be more of a problem.
Whether Excel indeed has the focus, and how (if so) it’s passing the key sequence to the terminal, sounds to me like a question for the documentation and/or
pywinauto issue tracker.
A 2nd ctrl-s is not supposed to work like that you are supposed to type ctrl-q to start output again. But hey, windows, what can you do?
The new console implementation that was introduced in Windows 10 (conhost v2 and openconsole) doesn’t implement Ctrl+S pausing. It’s only implemented by the legacy console (conhost v1). The new console still supports the pause/break key. In either case, it’s not actually a terminal XON/XOFF implementation, so pressing any key will resume the console, including Ctrl+S. It doesn’t have to be Ctrl+Q (DC1/XON). In order for this to block a console program, it would have to be doing all of its work on the same thread that’s writing to the console.