Python Forum
How to specify a Unicode character with Autokey keyboard.sendkeys()?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to specify a Unicode character with Autokey keyboard.sendkeys()?
#1
I am attempting to send Unicode characters using Linux Autokey's 'keyboard.send_keys' command. The example below is for typing an mdash.
I am using Autokey-py3 v0.93.10 software which is Python 3 based. (in Linux Mint 18.2) Unfortunately none of the following attempts work.

keyboard.sendkeys("—")

keyboard.sendkeys(u"\u2014")

Also tried this which I copied from unicode.py:

import.paste_character("—")

Can someone advise me what I am missing? Any help or direction is greatly appreciated.
Reply
#2
(Oct-29-2017, 06:35 PM)ineuw Wrote: Unfortunately none of the following attempts work.

is not helpful, you need to post a runnable piece of code and any error codes in their entirety, both between their respective tags. Refer to BBCode help topic on how to post.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
(Oct-29-2017, 07:52 PM)sparkz_alot Wrote:
(Oct-29-2017, 06:35 PM)ineuw Wrote: Unfortunately none of the following attempts work.

is not helpful, you need to post a runnable piece of code and any error codes in their entirety, both between their respective tags. Refer to BBCode help topic on how to post.

Please accept my apologies.

The keyboard key combination Alt= to which I assigned the output of the mdash ("—") but any keyboard combination results in the same.

The output was about 3,000 lines but I removed the duplicate lines that display the key polling of the same keys over and over again. I indicated with (removed duplicate entries).

With running Autokey --verbose in the terminal, the following was the relevant output.

ineuw@maccin18 ~ $ autokey --verbose
2017-10-29 21:03:49,930 INFO - root - Initialising application
2017-10-29 21:03:49,944 INFO - root - Initialise global hotkeys
2017-10-29 21:03:49,944 INFO - config-manager - Loading config from existing file: /home/ineuw/.config/autokey/autokey.json
2017-10-29 21:03:49,945 DEBUG - config-manager - Loading folder at '/home/ineuw/.config/autokey/data/english'
2017-10-29 21:03:49,995 INFO - config-manager - Configuration changed - rebuilding in-memory structures
2017-10-29 21:03:49,996 DEBUG - inotify - Adding watch for /home/ineuw/.config/autokey/data/english
2017-10-29 21:03:49,996 INFO - config-manager - Successfully loaded configuration
2017-10-29 21:03:49,996 DEBUG - inotify - Adding watch for /home/ineuw/.config/autokey/data
2017-10-29 21:03:49,996 DEBUG - inotify - Adding watch for /home/ineuw/.config/autokey
2017-10-29 21:03:49,997 DEBUG - config-manager - Global settings: {'columnWidths': [127, 40, 548], 'promptToSave': True, 'isFirstRun': False, 'showTrayIcon': True, 'windowDefaultSize': [1278, 738], 'notificationIcon': 'autokey-status', 'showToolbar': True, 'serviceRunning': True, 'menuTakesFocus': False, 'hPanePosition': 365, 'triggerItemByInitial': False, 'enableQT4Workaround': False, 'undoUsingBackspace': True, 'workAroundApps': '.*VirtualBox.*|krdc.Krdc', 'sortByUsageCount': False, 'scriptGlobals': {}, 'interfaceType': 'XRecord'}
2017-10-29 21:03:49,997 INFO - service - Starting service
2017-10-29 21:03:50,042 DEBUG - interface - Modifier masks: {'<super>': 64, '<shift>': 1, '<alt_gr>': 128, '<numlock>': 16, '<ctrl>': 4, '<hyper>': 64, '<meta>': 8, '<capslock>': 2, '<alt>': 8}
2017-10-29 21:03:50,490 DEBUG - interface - Alt-Grid: XK_Alt_R, 65514
2017-10-29 21:03:50,490 DEBUG - interface - <map object at 0x7f8195ccad30>
2017-10-29 21:03:50,490 DEBUG - interface - X Server Keymap
2017-10-29 21:03:50,490 DEBUG - interface - [\] : [(51, 0), (51, 2), (51, 4)]
2017-10-29 21:03:50,491 DEBUG - interface - [|] : [(51, 1), (51, 3), (94, 4), (51, 5), (94, 6)]
2017-10-29 21:03:50,491 DEBUG - interface - [`] : [(49, 0), (49, 2), (49, 4)]

2017-10-29 21:03:50,510 DEBUG - iomediator - Set modifier <capslock> to False
2017-10-29 21:03:50,510 DEBUG - iomediator - Set modifier <numlock> to False

(removed duplicate entries)

2017-10-29 21:03:50,511 DEBUG - interface - Grabbing hotkey: ['<alt>'] 'b'

2017-10-29 21:03:50,527 INFO - interface - XRecord interface thread starting
2017-10-29 21:03:50,527 DEBUG - interface - Grabbing hotkey: ['<super>'] 'i'
2017-10-29 21:03:50,529 INFO - service - Service now marked as running

2017-10-29 21:03:50,540 DEBUG - phrase-menu - Sorting phrase menu by item name/title

"sni-qt/13906" WARN 21:03:50.556 void StatusNotifierItemFactory::connectToSnw() Invalid interface to SNW_SERVICE

2017-10-29 21:03:50,595 DEBUG - interface - Grabbing hotkey: ['<alt>'] '='

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3082, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3083, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3084, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3085, major_opcode = 33, minor_opcode = 0
2017-10-29 21:03:50,890 DEBUG - interface - Grabbing hotkey: ['<super>'] 'p'
2017-10-29 21:03:50,891 DEBUG - interface - Grabbing hotkey: ['<super>'] 'p'
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3092, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3093, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3094, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3095, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3107, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3108, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3109, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3110, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3617, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3618, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3619, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 3620, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3627, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3628, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3629, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 3630, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3642, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3643, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 3644, major_opcode = 33, minor_opcode = 0
X protocol error:

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 5813, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 5814, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 5815, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 5816, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 5823, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 5824, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 5825, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 5826, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 5838, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 5839, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 5840, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 5841, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 152, sequence_number = 7126, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 152, sequence_number = 7127, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 152, sequence_number = 7128, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 152, sequence_number = 7129, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 10153, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 10154, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 10155, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 75497475, sequence_number = 10156, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 10163, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 10164, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 10165, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 113246340, sequence_number = 10166, major_opcode = 33, minor_opcode = 0

(removed duplicate entries)

X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 10178, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 10179, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 10180, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 65034963, sequence_number = 10181, major_opcode = 33, minor_opcode = 0

2017-10-29 21:03:51,693 DEBUG - interface - Grabbing hotkey: ['<super>'] 'e'

(removed duplicate entries)

2017-10-29 21:04:00,022 DEBUG - service - Received mouse click - resetting buffer

(removed duplicate entries)

2017-10-29 21:05:48,422 DEBUG - service - Received mouse click - resetting buffer

2017-10-29 21:05:51,652 DEBUG - iomediator - <alt> pressed

2017-10-29 21:05:52,441 DEBUG - service - Raw key: '=', modifiers: ['<alt>'], Key: =
2017-10-29 21:05:52,442 DEBUG - service - Window visible title: 'ineuw@maccin18 ~', Window class: 'gnome-terminal-server.Gnome-terminal'
2017-10-29 21:05:52,442 INFO - service - Matched hotkey phrase/script with prompt=False
2017-10-29 21:05:52,443 DEBUG - service - Script runner executing: Script('alt-=')
2017-10-29 21:05:52,443 DEBUG - service - Ignored locking error in handle_keypress
2017-10-29 21:05:52,444 DEBUG - iomediator - Send via event interface
2017-10-29 21:05:52,448 DEBUG - interface - Sending string: '—'
2017-10-29 21:05:52,848 DEBUG - iomediator - <alt> released
2017-10-29 21:06:14,691 DEBUG - service - Received mouse click - resetting buffer

(removed duplicate entries)

2017-10-29 21:06:25,859 DEBUG - service - Received mouse click - resetting buffer

(removed duplicate entries)

2017-10-29 21:06:35,414 INFO - root - Displaying configuration window
2017-10-29 21:06:35,425 DEBUG - service - Received mouse click - resetting buffer
2017-10-29 21:06:38,083 INFO - root - Shutting down
2017-10-29 21:06:38,093 INFO - service - Service shutting down

(removed duplicate entries)

autokey.interface BadWindow(<Xlib.display._BaseDisplay object at 0x7f819f22bcc0>, b'\x00\x03\xb3@\x05a\xe0\x03\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
autokey.interface BadWindow(<Xlib.display._BaseDisplay object at 0x7f819f22bcc0>, b'\x00\x03\xb4@\x05a\xe0\x03\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

(removed duplicate entries)

2017-10-29 21:06:42,344 INFO - config-manager - Persisting configuration
2017-10-29 21:06:42,344 INFO - config-manager - Backing up existing config file
2017-10-29 21:06:42,345 INFO - config-manager - Finished persisting configuration - no errors
2017-10-29 21:06:42,346 DEBUG - inotify - Reporting IN_MODIFY event at /home/ineuw/.config/autokey/autokey.json~
2017-10-29 21:06:42,347 DEBUG - inotify - Reporting IN_MODIFY event at /home/ineuw/.config/autokey/autokey.json
2017-10-29 21:06:42,347 DEBUG - inotify - Reporting IN_MODIFY event at /home/ineuw/.config/autokey/autokey.json
2017-10-29 21:06:43,349 INFO - inotify - Shutting down file monitor
2017-10-29 21:06:43,350 DEBUG - root - All shutdown tasks complete... quitting
Reply
#4
I guess this is not possible with Python 3. Although it recognizes Unicode text with copy and paste, but crashed when attempted the same with Python 2.7. So,it does recognize Unicode characters.

Would anybody give me some idea how to go about resolving this issue.
Linux Mint Cinnamon 21.3 - Python 3.10.12 - Autokey-gtk 0.96.0 as of 2024-01-13.
Reply
#5
See this. I used it the other day to automate some tasks. 
All you need to do is just to pass the key names to the pyautogui.hotkey method. Example:

 pyautogui.hotkey( 'ctrl ', 'shift', 'S') # CTRL+SHIFT+S
A list of all key names is in pyautogui.KEY_NAMES and all keyboard keys are in pyautogui.KEYBOARD_KEYS
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
wavic, much thanks. Now I have to adopt it to my needs which means a lot of reading and practice.

P.S: "dosvidanya" in Microsoftese means the vidanya version of DOS.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SendKeys not working SanjayGMusafir 4 448 Jan-16-2024, 12:07 PM
Last Post: EdwardMatthew
  width of Unicode character Skaperen 6 2,690 Sep-27-2021, 12:41 AM
Last Post: Skaperen
  [solved] unexpected character after line continuation character paul18fr 4 3,378 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,149 Jul-13-2020, 07:05 PM
Last Post: snippsat
  Search box python selenium sendkeys dorabajji 0 1,479 Mar-10-2020, 09:41 AM
Last Post: dorabajji
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,719 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Replace changing string including uppercase character with lowercase character silfer 11 6,124 Mar-25-2019, 12:54 PM
Last Post: silfer
  # of bytes used to store a Unicode character insearchofanswers87 3 2,691 Jan-19-2019, 04:01 PM
Last Post: ichabod801
  clean unicode string to contain only characters from some unicode blocks gmarcon 2 3,949 Nov-23-2018, 09:17 PM
Last Post: Gribouillis
  Trying to use win32 Sendkeys to log into database overnight statiCat 0 4,161 Apr-28-2018, 03:59 PM
Last Post: statiCat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020