moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.74k stars 244 forks source link

Backspace will delete multiple codepoints rather than a single codepoint #514

Closed SpecialCharacter closed 1 year ago

SpecialCharacter commented 1 year ago

Made a new bug report from rests of: https://github.com/moses-palmer/pynput/issues/478

Description Backspace deletes multiple codepoints rather than a single codepoint (= expected behaviour). That happens only with MacOS, not with Windows.

Platform and pynput version MacOS Catalina 10.15.7 pynput version unknown

To Reproduce ā # two codepoints

keyboard.Controller().tap(Key.left)
keyboard.Controller().type('\b')
keyboard.Controller().tap(Key.right)
Quartz.CGEventKeyboardSetUnicodeString(event, 1, '¨')

Expected outcome: ā --> ä # each two codepoints

"Had a closer look at it and it seems MacOS implements backspace in a different way than Windows does (which is unfortunate). Under Windows, I am able to change combining diacritics while meandering around the base characters (a¨ --> aˉ). Contrary, MacOS will delete the combining diacritics along with its base character."

"I asked around in various forums and got this answer: "It's more likely that the backspace action deleted the entire grapheme made up of multiple codepoints rather than a single codepoint. Whatever is happening, it's probably a feature of whatever application is actually handling keyboard input (e.g., iTerm2, your IDE) or a library/framework that Python is using (e.g., GNU Readline), not Python specifically." Does that ring any bell?"

"Have you had time to look into the issue? Forums suggested the faulty implementation comes from a library/framework that Python is using,"

moses-palmer commented 1 year ago

Thank you for your report.

To be frank, I think this is one of those platform dependent issues. To me is seems more reasonable to delete the entire grapheme rather that the diacritic on backspace; that is what I would assume Windows did as well.

I honestly do not think this is solvable from this library---pynput can handle input events, not text buffers in widget toolkits---so I will close it. If you think otherwise, please reopen.