Python Forum

Full Version: How to specify a Unicode character with Autokey keyboard.sendkeys()?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
(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.
(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
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.
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
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.