-1

How can I write a variable in python on the computer? I want to paste a text and I can't use pyautogui because the text is in Hebrew. this is my code:

from pynput.keyboard import Key, Listener
import pyautogui as pya
import pyperclip

def copy_clipboard():
    pya.hotkey('ctrl', 'c')
    return pyperclip.paste()

def changeLanguge(text):
    finelText = ""
    data = {
        't': 'א',
        'c': 'ב',
        'd': 'ג',
        's': 'ד',
        'v': 'ה',
        'u': 'ו',
        'z': 'ז',
        'j': 'ח',
        'y': 'ט',
        'h': 'י',
        'f': 'כ',
        'k': 'ל',
        'n': 'מ',
        'b': 'נ',
        'x': 'ס',
        'g': 'ע',
        'p': 'פ',
        'e': 'ק',
        'm': 'צ',
        'r': 'ר',
        'a': 'ש',
        ',': 'ת',
        'w': "'",
        'q': '/',
        'i': 'ן',
        'o': 'ם',
        ';': 'ף',
        'l': 'ך',
        '.': 'ץ',
        '/': '.',
    }
    for char in text:
        if char in data:
            finelText += data[char]
        else:
            finelText += char
    
    return finelText


def on_press(key):
    if str(key) == 'Key.f9':
        var = copy_clipboard()
        changeLanguge(var)
        pya.typewrite(changeLanguge(var)) #here i want to paste the text

with Listener(on_press=on_press) as listener:
    listener.join()

The purpose of the program is to convert text from English into Hebrew when f9 is pressed. the converting of the text works but I can't paste thetext into the computer.

  • Can you provide some more information what you mean with `writing a variable in python to the computer`? If you are referring to the clipboard, you can take a look at this question: https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard If you are referring to saving information, then I'd suggest just writing it to a file using this code: `with open("file.txt", "w") as handle: handle.write(my_var)` – Sybren Zwetsloot Dec 05 '21 at 13:21

1 Answers1

0

try pynputs controller:

keyboard.type('your text')

https://pynput.readthedocs.io/en/latest/keyboard.html

cyFx
  • 104
  • 5