ActivityPub Viewer

A small tool to view real-world ActivityPub objects as JSON! Enter a URL or username from Mastodon or a similar service below, and we'll send a request with the right Accept header to the server to view the underlying object.

Open in browser →
{ "@context": [ "https://join-lemmy.org/context.json", "https://www.w3.org/ns/activitystreams" ], "type": "Page", "id": "https://lemmy.world/post/27385536", "attributedTo": "https://lemmy.world/u/zkfcfbzr", "to": [ "https://programming.dev/c/python", "https://www.w3.org/ns/activitystreams#Public" ], "name": "Why is pynput typing incorrect output, but only on Linux?", "cc": [], "content": "<p>I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect.</p>\n<p>I recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way that’s both consistent and inconsistent.</p>\n<p>The simplest possible case I found that reproduces the error is this script:</p>\n<pre style=\"background-color:#ffffff;\">\n<span style=\"font-weight:bold;color:#a71d5d;\">import </span><span style=\"color:#323232;\">time\n</span><span style=\"font-weight:bold;color:#a71d5d;\">from </span><span style=\"color:#323232;\">pynput </span><span style=\"font-weight:bold;color:#a71d5d;\">import </span><span style=\"color:#323232;\">keyboard\n</span><span style=\"color:#323232;\">\n</span><span style=\"font-style:italic;color:#969896;\"># Sleep statement is just to give time to move the mouse cursor to a text input field\n</span><span style=\"color:#323232;\">time.sleep(</span><span style=\"color:#0086b3;\">2</span><span style=\"color:#323232;\">)\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">my_kb </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#323232;\">keyboard.Controller()\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">text </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#183691;\">&#39;πŸ†&#39; </span><span style=\"font-style:italic;color:#969896;\"># Eggplant emoji\n</span><span style=\"color:#323232;\">my_kb.type(text)\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">time.sleep(</span><span style=\"color:#0086b3;\">1</span><span style=\"color:#323232;\">)\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">text </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#183691;\">&#39;π•₯𝕖𝕀π•₯&#39; </span><span style=\"font-style:italic;color:#969896;\"># blackboard bold test\n</span><span style=\"color:#323232;\">my_kb.type(text)\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">time.sleep(</span><span style=\"color:#0086b3;\">1</span><span style=\"color:#323232;\">)\n</span><span style=\"color:#323232;\">\n</span><span style=\"color:#323232;\">text </span><span style=\"font-weight:bold;color:#a71d5d;\">= </span><span style=\"color:#183691;\">&#39;𝐭𝐞𝐬𝐭&#39; </span><span style=\"font-style:italic;color:#969896;\"># bold test\n</span><span style=\"color:#323232;\">my_kb.type(text)\n</span></pre>\n<p>When I run that script right now, it produces the output β€œπŸ†π•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭”. And if I run it again, it’ll produce the same output. And if I change the eggplant emoji to something else, like the regular character β€˜A’, it will still produce the same output (specifically β€œAπ•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭”). But… If I log out and log back in, then the output changes to something else that’s still wrong, but differently. For example, when I changed the eggplant to a regular β€˜A’, then relogged, the output became β€œAπ•₯𝕖𝕖π•₯π­πžπžπ­β€. And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings don’t change, then the incorrect outputs don’t change on relog - but if they do, then they do.</p>\n<p>In the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get β€œπŸ†π•–π•€πŸ†β€. This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions.</p>\n<p>I am very new to Linux. I’m on Linux Mint. I’m running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters.</p>\n", "mediaType": "text/html", "source": { "content": "I have a rather large Python script that I use as basically a replacement for autohotkey. It uses pynput for keyboard and mouse control - and at least on Windows, it works exactly how I expect. \n\nI recently started dual-booting with Linux and have been trying to get the script to work here as well. It does work but with mixed results - in particular, I found that pynput has bizarrely wrong output for special characters, in a way that's both consistent and inconsistent. \n\nThe simplest possible case I found that reproduces the error is this script: \n\n```python\nimport time\nfrom pynput import keyboard\n\n# Sleep statement is just to give time to move the mouse cursor to a text input field\ntime.sleep(2)\n\nmy_kb = keyboard.Controller()\n\ntext = 'πŸ†' # Eggplant emoji\nmy_kb.type(text)\n\ntime.sleep(1)\n\ntext = 'π•₯𝕖𝕀π•₯' # blackboard bold test\nmy_kb.type(text)\n\ntime.sleep(1)\n\ntext = '𝐭𝐞𝐬𝐭' # bold test\nmy_kb.type(text)\n```\n\nWhen I run that script right now, it produces the output \"πŸ†π•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭\". And if I run it again, it'll produce the same output. And if I change the eggplant emoji to something else, like the regular character 'A', it will still produce the same output (specifically \"Aπ•₯π•₯𝕀π•₯𝐭𝐭𝐬𝐭\"). But... If I log out and log back in, then the output changes to something else that's still wrong, but differently. For example, when I changed the eggplant to a regular 'A', then relogged, the output became \"Aπ•₯𝕖𝕖π•₯𝐭𝐞𝐞𝐭\". And then that wrong output will keep being the same wrong output until I log out and back in again. If the test strings don't change, then the incorrect outputs don't change on relog - but if they do, then they do. \n\nIn the larger script, errors seemed to chain together somehow - like if I produced an eggplant emoji, then tried to write blackboard bold test, I would get \"πŸ†π•–π•€πŸ†\". This is despite verifying just before running the pynput.keyboard.Controller.type function that what it was about to type was correct. The issue also happens if I type it character-by-character with press and release functions. \n\nI am very new to Linux. I'm on Linux Mint. I'm running this in a python3 venv that just has pynput and two other external libraries installed. ChatGPT thinks the issue might be related to X11. The issue does not occur at all on Windows, using the exact same code. On Linux there seems to be no issues with typing regular text, just special characters. ", "mediaType": "text/markdown" }, "attachment": [], "sensitive": false, "published": "2025-03-25T18:26:08.617221Z", "updated": "2025-03-25T18:47:44.655567Z", "language": { "identifier": "en", "name": "English" }, "audience": "https://programming.dev/c/python", "tag": [ { "href": "https://lemmy.world/post/27385536", "name": "#python", "type": "Hashtag" } ] }