如何在 Python 3.7 中使用 Mac OSX 上的 IDLE 监视按键

How to monitor key presses in Python 3.7 using IDLE on Mac OSX

在 Mac 上使用 Python 3.7 和 IDLE。我希望能够监控按键并立即 return 字符或其 ASCII 或 Unicode 值。我看不到如何在 Idle 中使用 pynput。有什么想法吗?

你不能。 IDLE 使用 tcl/tk GUI 框架的 tkinter 接口。 IDLE 文档当前有一个标题为 'Running user code' 的章节。

When Shell has the focus, it controls the keyboard and screen. This is normally transparent, but functions that directly access the keyboard and screen will not work. These include system-specific functions that determine whether a key has been pressed and if so, which.