28 April 2026
Musk ElongYes I know, however the problems we can still use \\to print single \ right?
Right, i did it in my example
Musk ElongOn the other hand why I cannot share my photos on this group
Rules in our groups are strictly enforced. It is strongly recommended to read our rules before engaging in any other activity!
George 392.85 °CIn [8]: print(" /\\\\")
...: print(" / \\\\")
...: print("/____\\\\")
...: print("| |")
...: print("|_____|")
/\\
/ \\
/____\\
| |
|_____|
Yes this 3 back slashes work for me thx
Hi,
I'm building a Python project to insert text into the currently focused Windows application at the caret position (triggered by a hotkey).
I'm using user32.SendMessageW with EM_REPLACESEL, but it only works with native apps like Notepad or Explorer, and fails with browsers, VS Code, and other modern apps.
Here is my current code:
import ctypes
from ctypes import wintypes
user32 = ctypes.WinDLL("user32", use_last_error=True)
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
EM_REPLACESEL = 0x00C2
user32.GetForegroundWindow.restype = wintypes.HWND
user32.GetFocus.restype = wintypes.HWND
user32.AttachThreadInput.argtypes = [
wintypes.DWORD,
wintypes.DWORD,
wintypes.BOOL,
]
user32.GetWindowThreadProcessId.argtypes = [
wintypes.HWND,
ctypes.POINTER(wintypes.DWORD),
]
user32.GetWindowThreadProcessId.restype = wintypes.DWORD
kernel32.GetCurrentThreadId.restype = wintypes.DWORD
user32.SendMessageW.argtypes = [
wintypes.HWND,
wintypes.UINT,
wintypes.WPARAM,
wintypes.LPCWSTR,
]
user32.SendMessageW.restype = ctypes.c_ssize_t
def get_focused_hwnd():
foreground = user32.GetForegroundWindow()
current_thread = kernel32.GetCurrentThreadId()
foreground_thread = user32.GetWindowThreadProcessId(foreground, None)
user32.AttachThreadInput(current_thread, foreground_thread, True)
try:
focused = user32.GetFocus()
finally:
user32.AttachThreadInput(current_thread, foreground_thread, False)
return focused
def insert_text(text: str):
hwnd = get_focused_hwnd()
if not hwnd:
raise RuntimeError("No focused control found")
user32.SendMessageW(hwnd, EM_REPLACESEL, True, text)
if __name__ == "__main__":
insert_text("Hello, world!")
What's the recommended approach to support all apps (e.g., browsers, VS Code, Electron)?
Also, I don't want use clipboard paste.
Thanks.
Scott LiuHi,
I'm building a Python project to insert text into the currently focused Windows application at the caret position (triggered by a hotkey).
I'm using user32.SendMessageW with EM_REPLACESEL, but it only works with native apps like Notepad or Explorer, and fails with browsers, V
the reason your current code is fked is that SendMessage with EM_REPLACESEL bruh thats old school code..
modern apps like VS Code dont actually use the standard windows text boxes.. They draw their own interfaces from scratch using web tech or custom engines.. so they don't even know what an em_replacesel message is 🫠
Scott LiuHi,
I'm building a Python project to insert text into the currently focused Windows application at the caret position (triggered by a hotkey).
I'm using user32.SendMessageW with EM_REPLACESEL, but it only works with native apps like Notepad or Explorer, and fails with browsers, V
I think that to be able to do it with chromium-based software, you'd need the help of an extension, but that's outside the scope of this group. You may ask in the off-topic group
30 April 2026
Scott LiuHi,
I'm building a Python project to insert text into the currently focused Windows application at the caret position (triggered by a hotkey).
I'm using user32.SendMessageW with EM_REPLACESEL, but it only works with native apps like Notepad or Explorer, and fails with browsers, V
Up Stair ; .. return focused ->
PippiI just read somewhere that pytorch lightning has been compromised.
Well "somewhere" is quite unspecific, have you verified that?
🚨 Supply chain attacks are escalating...
A widely used AI dev tool, PyTorch Lightning, was compromised on PyPI and turned into a credential stealer.
→ Malicious code runs on import
→ No user action needed
→ Credentials silently stolen
Read: https://thehackernews.com/2026/04/pytorch-lightning-compromised-in-pypi.html