Search code examples
pythonpython-2.7xdotool

Pasting on input field via python


I am having difficulty finding a proper solution to paste my input into a input field. I am using the library Xdo.

What am i doing ?

The Python file is running in the backend.

The program fetches data from a Smart card.

Data returned are numerical / English and Thai.

Then in browser, when I click to a input button, then the values are to be pasted in to the input button.

What is the issue?

The numerical data (ID card/ Birthday ) is printed correctly in the browser.

The thai texts are giving trouble. They are not inserted or partially inserted sometimes.

*This used to work in **windows machine but I was using a different library (SendKeys for windows program). But using Xdo on linux is giving me trouble.***

Following is my sample code

 from xdo import Xdo
 xdo = Xdo()
 res = convert_data(resultlist)
 title_th = res['title_th']
 fname_th = res['fname_th']
 lname_th = res['lname_th']
 birthday = res['birthday']
 address = res['address']

 win_id = xdo.get_focused_window()
 xdo.enter_text_window(win_id, res['id'])
 xdo.send_keysequence_window(win_id,'Tab')
 xdo.enter_text_window(win_id,str(title_th.decode('tis-620')))
 xdo.send_keysequence_window(win_id,'Tab')
 xdo.enter_text_window(win_id,str(fname_th.decode('tis-620')))
 xdo.send_keysequence_window(win_id,'Tab')
 xdo.enter_text_window(win_id,str(lname_th.decode('tis-620')))
 xdo.send_keysequence_window(win_id,'Tab')
 xdo.enter_text_window(win_id,str(birthday.decode('tis-620')))
 xdo.send_keysequence_window(win_id,'Tab')
 xdo.enter_text_window(win_id,str(address.decode('tis-620')))
 xdo.send_keysequence_window(win_id,'Tab')

The Following is a sample image.

As you can see, some Thai texts are partially entered and others are skipped.

enter image description here

Looking for any suggestions, or any alternatives to my current solution is highly appreciated.


Solution

  • I managed to solve the above issue without depending on Python libxdo tools.

    I have managed to solve by using command line xdotool and xsel .

    Check this link for detailed information SOLVED