I'm basically trying to write a code in python that print some letter using module pyautogui. I need it to write at (@) because i want to use the code to write in a facebook post and i need it to tag my friends. The problem is that my keyboard layout is italian and i can't get the at to be typed. I tried also to make the keyboard language change during the digitation but I didn't get it work. This is the code:
import pyautogui
pyautogui.typewrite('@')
didn't work. Output:
>>>
So I tried to make the code changing keyboard layout (because i noticed that if i manually set keyboard layout to english:
pyautogui.hotkey('shift', '2')
works). So this is the code, but instead of @ i get " which is (shift + 2) in italian keyboard layout.
import ctypes
from ctypes import wintypes
def change_layout(locale_id_bytes):
KLF_ACTIVATE = 0x00000001
klid = ctypes.create_string_buffer(locale_id_bytes)
user32_dll = ctypes.WinDLL("user32")
kernel32_dll = ctypes.WinDLL("kernel32")
LoadKeyboardLayout = user32_dll.LoadKeyboardLayoutA
LoadKeyboardLayout.argtypes = [wintypes.LPCSTR, wintypes.UINT]
LoadKeyboardLayout.restype = wintypes.HKL
GetLastError = kernel32_dll.GetLastError
GetLastError.restype = wintypes.DWORD
klh = LoadKeyboardLayout(klid, KLF_ACTIVATE)
print("{} returned: {}".format(LoadKeyboardLayout.__name__, hex(klh)))
print("{} returned: {}".format(GetLastError.__name__, GetLastError()))
def digit_at ():
change_layout (b"00000409")
import pyautogui
pyautogui.hotkey('shift', '2')
change_layout (b"00000410")
digit_at()
output:
LoadKeyboardLayoutA returned: 0x4090409
GetLastError returned: 0
LoadKeyboardLayoutA returned: 0x4100410
GetLastError returned: 0
"
>>>
User contributions licensed under CC BY-SA 3.0