Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved os x server (various things) #162

Merged
merged 7 commits into from
Jul 17, 2018

Conversation

dylan-chong
Copy link
Contributor

@dylan-chong dylan-chong commented Jul 8, 2018

I've been using @seananderson 's set up for over a year now and it's been working amazingly! I completely forgot that I had done so, so I thought I'd better submit these changes. @seananderson I hope you don't mind me stealing some of your commits!

Fixes:

'caret': '^',
'colon': ':',
'comma': ',',
'dollar': '$',
'dot': '.',
'dquote': '"',
'dquote': '\\\"',
Copy link
Contributor Author

@dylan-chong dylan-chong Jul 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes errors

@@ -96,15 +96,15 @@
'apostrophe': "'",
'asterisk': '*',
'at': '@',
'backslash': '\\',
'backslash': '\\\\',
Copy link
Contributor Author

@dylan-chong dylan-chong Jul 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix errors

@dylan-chong dylan-chong changed the title WIP IGNORE THIS FOR NOW Improved os x (various things) WIP IGNORE THIS FOR NOW Improved os x server (various things) Jul 8, 2018
end repeat
end tell
'''.format(text=text))
script.run()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seananderson ❤️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you only need keystroke "{text}" to use simulated keystrokes instead of pasting; however, about a year ago sometimes keystrokes started getting missed. As far as I can tell, some update to the operating system changed this. That's when I added a micro delay and iterated over each character. seananderson@5e8a6de

It's possible this is unique to my set up or that other people would need a different delay. Obviously, it's a bit faster if you can avoid the delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daaang keystroke "{text}" Is so much faster!

I have not been able to replicate your missing keystrokes bug, maybe Apple fixed as it has been a year. (I am running 10.13.6 by the way).

Would you be able to see if running the script below capitalises words correctly? Just beware that this will start typing stuff after two seconds so make sure you have a text field open and selected after clicking run on the script editor

delay 2
tell application "System Events"
	keystroke "# 1: Testing hello. This is a test to Test that the words are capitalised Correctly"
	keystroke "# 2: Testing hello. This is a test to Test that the words are capitalised Correctly"
	keystroke "# 3: Testing hello. This is a test to Test that the words are capitalised Correctly"
end tell

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keystroke "{text}" seems to be working for me now. I'd forgotten just how much faster this is!

Your test does print the words with the proper capitalization for me. If doesn't for you then it might have to do with the auto correction and auto capitalization settings in the operating system ("Correct spelling automatically" and "Capitalize words automatically" in the Keyboard Preferences pane). I think it was at the time that those were introduced that I first had the problems. I have them turned off.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried turning on the capitalise words automatically and correct spelling automatically options and can't replicate the bug. I think i will put it back to keystroke "{text}" and submit another pull request if I happen to replicate the but somehow

@@ -429,9 +429,6 @@ def key_press(
key_to_press = _KEYCODE_TRANSLATION.get(key.lower(), None)
command = 'key code "{0}"'.format(key_to_press)

if key_to_press is None:
raise RuntimeError("Don't know how to handle keystroke {0}".format(key))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting the stuff out seem to work to me for the past year. Solves #118

@@ -80,7 +80,7 @@


_MOD_TRANSLATION = {
'alt': 'alt',
'alt': 'option',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed errors

'option': 'option',
'control': 'control',
'alt': 'option',
'ctrl': 'control',
Copy link
Contributor Author

@dylan-chong dylan-chong Jul 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seananderson Could you enlighten us on what this does (you did this on commit with message Fix modifier keys for OS X). Modifier keys through a Key seem to work with or without this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm not sure. I made that change a long time ago when I was first starting out and might have just matched what I did above for _MOD_TRANSLATION. It doesn't seem to matter what I change the keys or values to here in terms of what happens when I run something like Key('c-a'). Is it possible these only affect the functionality to press and hold down or release modifier keys? I don't use that functionality. If I'm reading the code right, _MODIFIER_KEY_DIRECT only gets used to check whether a key is a modifier and can therefore be held down or released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm you are correct. I will edit the commit message to make this explicit

@dylan-chong dylan-chong changed the title WIP IGNORE THIS FOR NOW Improved os x server (various things) Improved os x server (various things) Jul 8, 2018
@calmofthestorm
Copy link
Member

I haven't forgotten about this. I'll try to take a look soon.

@seananderson
Copy link
Contributor

Thanks for putting together the pull request, @dylan-chong! I'm glad you found the changes useful and I'm thrilled to have someone else to debug this with as macOS evolves. I'm pretty dependent on it for my work.

@calmofthestorm
Copy link
Member

I looked over the diff and I don't have any comments; these all look like reasonable changes. As I noted above, I unfortunately don't have any way to actually test this on OS X, but LGTM.

Should I go ahead and merge this?

@dylan-chong
Copy link
Contributor Author

Not just yet. I want to investigate the comments from sean anderson before merging

seananderson and others added 4 commits July 15, 2018 21:12
…')`)

This is a squash of two commits by github user @seananderson:
- Fix modifier keys for OS X
- Switch 'control' to 'ctrl' in OS X server
- maximizes compatibility with applications
- stops clobbering the clipboard history
- works with auto text expansion
- minor decrease in speed of text appearing
Recent operating system update appears to require this
Otherwise the typing can be too quick and letters are lost
...on os x 10.13.6. May be apple fixed the bug?

See here for discussion:
https://github.com/dictation-toolbox/aenea/pull/162/files#r200833905

This reverts commit b9dcd90.
@dylan-chong
Copy link
Contributor Author

@calmofthestorm Ready for merge now. I have just pushed one more commit in case you want to check it

@calmofthestorm
Copy link
Member

Thank you both for your efforts on this change.

@calmofthestorm calmofthestorm merged commit 4984f0c into dictation-toolbox:master Jul 17, 2018
simonireilly pushed a commit to simonireilly/aenea that referenced this pull request Aug 3, 2018
dylan-chong added a commit to dylan-chong/aenea that referenced this pull request Sep 5, 2018
…cessary"

This reverts commit f07b6ec.

I am re-reverting this because I realised that MacVim and VimR, among other
applications, often missed big chunks of `Text`. I originally reverted
this change in dictation-toolbox#162 on github.
dylan-chong added a commit to dylan-chong/aenea that referenced this pull request Sep 9, 2018
…cessary"

This reverts commit f07b6ec.

I am re-reverting this because I realised that MacVim and VimR, among other
applications, often missed big chunks of `Text`. I originally reverted
this change in dictation-toolbox#162 on github.
@dylan-chong dylan-chong deleted the improved-os-x branch October 5, 2018 06:25
simonireilly added a commit to simonireilly/aenea that referenced this pull request Feb 9, 2020
* Add wayland server using evdev

* Add F1-F12 keys

* Add < and > management

* Add commentaries

* Wayland (evdev): new implementation to support several keymap

Only tested with test-client.py (from X11 directory).

* Fix key press

"Press" was buggy because each key was released before other have been pressed.

* Remove debug print

* Adjust readme virtual machine specs

I have been using only one gigabyte of RAM with the virtual machine for
many months, and it works very well.

* Revert "Revert "Add micro delay with OSX keypresses" seems to be a necessary"

This reverts commit f07b6ec.

I am re-reverting this because I realised that MacVim and VimR, among other
applications, often missed big chunks of `Text`. I originally reverted
this change in dictation-toolbox#162 on github.

* Use only double quotes

* Wayland: implement mouse click

* Use a different version of dragonfly on the readme https://github.com/Danesprite/dragonfly

* Fixed page up and page down not working on osx server

* Add typeables to dragonfly_mock.py

* Fix alias.py to work with tests, and fix a bug.

* Convert mocks to new-style classes...can't believe I'm typing this...what was I thinking?

* Change configuration.py to fall back to mocks for tests.

* Remove obsolete tests for AlwaysContext/NeverContext moved out of proxy_contexts.py

* Fix a bug in the wayland server.

* Fix pyflakes warnings for most files; add a list of exemptions for ones that are impractical.

* Add Travis CI integration for the client unit tests.

Aenea's automated tests are, sadly, not great. We have a simple
integration test for the server that relies on X11, some basic unit
tests for the client library, and a bunch of untested code.

I don't think I'll be able to spend the time fully fixing this,
unfortunately, but we can at least set up CI for the tests we have to
prevent them from bit rotting again, and so that if other contributors
wish to add tests they can more easily do so.

I've also decided to start enforcing pyflakes clean for all new PRs
going forward; there is a list of exclusions in .nopyflakes for files
that would be impractical to fix for the time being. New PRs must not
introduce new pyflakes errors.

Both pyflakes and the client-side unit tests, such as they are, will now
run in Travis.

* Add HACKING.rst with notes on testing, CI, and style.

* Fix Travis link.

* Fix spelling errors.

* Fix missing equals translations in linux_x11 files

* Many minor readme improvements

* Correct readme numbering

* Pull request minor review changes

* Create OWNERS

* aenea server (x11): requires xprop

* Add a security_token to the linux_x11 server to prevent malicious web
pages from POSTing RPCs.

Please note that the protocol is still quite insecure, and this is just
a very basic check against a particularly serious and easy to exploit
attack. See the SECURITY section of the README for more information.

Thanks to @lunixbochs for finding this.

* Update recommendation to use script.

* Add warning to the Windows server.

* Add experimental support for security tokens to the OS X server.

Note that this is untested, since I don't have a good way to test things
on OS X at the moment.

borgmaster-relnote: n/a

* Fix security token not being set in aenea_client.py

* Add security token to windows server.

* Add security token support to Wayland server.

* Move security token checks into server/core.py (OSX & X11 only)

Security token checks have been moved into a new AeneaJSONRPCServer
class in core.py. This class patches RPC functions registered with
'server.register_function()' to add and check the required
'security_token' argument. Positional and key word arguments should
work.

A few notes:
- This allows Yapsy server plugins to work again.
- The PlatformRpcs classes and their RPC methods no longer accept
  'security_token' arguments.
- This will break the Wayland server implementation for now.

* Remove 'security_token' arguments from docstrings

* Make Travis CI build with Python 2.7

* Fix some minor problems with security checks

- Prevent possible TypeErrors in 'compare_security_token()' by checking
  if the received token object has the '__len__' method.
- Let the '_check_security_token' method handle missing 'security_token'
  keyword arguments instead of raising a ValueError.

* Fix a few problems with the Wayland server

- Add missing 'ctrl' alias for the 'control' key in evdevImpl.py.
- Add missing check for unicode objects in evdevImpl.py.
- Make 'AbstractKeyboardMapping' work with the builtin 'super' function
  by inheriting from 'object'.
- Rename the server's config.py file to config.py.example and use the
  standard "192.168.56.1" address instead of "0.0.0.0".
- Set the file encoding for azerty.py to utf-8.

* Fix Wayland server's security token support

* Added pagedown abd pageup

* Fix broken test-client.py script

The script now uses Aenea's security tokens correctly.

* Add missing entry for the "server" logger in AeneaLoggingManager

* Clarify usage of ``aenea/aenea.json``

* Documenting audio drift issue and fix

* Update README.rst

* Added Recognition Results plugin

* added docs for the recognition bar, added enabled variable to disable the bar by default

* added docs for the recognition bar, added enabled variable to disable the bar by default

* added enabled variable to disable the bar by default

* Change proxy contexts to support list parameters

This makes Aenea's proxy contexts work with list parameters that
dragonfly.AppContext supports.

* Remove imports for Dragonfly's sendinput structs

The sendinput structs (e.g. HardwareInput) are only available on
Windows. Importing dragonfly should work on other platforms if
these are removed.

* Changed Recognition Bar plugin name to Recognition Results, fixed linter errors, added more doc

*  _check_properties  checks for `none`

Co-authored-by: Cédric Chépied <cedric.chepied@gmail.com>
Co-authored-by: Dylan Chong <dylan.chong@icloud.com>
Co-authored-by: Alex Roper <alex@aroper.net>
Co-authored-by: Dane Finlay <Danesprite@posteo.net>
Co-authored-by: Graham Christensen <graham@grahamc.com>
Co-authored-by: LexiconCode <thequietplace@protonmail.com>
Co-authored-by: Kn0rk <knork@m1234.de>
Co-authored-by: Facundo Quiroga <facundoq@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aenea Dictation Client keystroke errors with OS X server
3 participants