t4ngo / dragonfly

ARCHIVED! - Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS) and Windows Speech Recognition (WSR)
GNU Lesser General Public License v3.0
364 stars 82 forks source link

Keyboard layout #38

Open haltuf opened 9 years ago

haltuf commented 9 years ago

Is there a specific Keyboard layout in Windows, that has to be active, for Dragonfly to work? If yes, didn't find any information in docs.

Example of script:

from dragonfly import Text a2 = Text("Hello world ( ) { }") a2.execute()

leads to this output:

Hello world } ] ^B ^N

which causes funny behaviour of IDE, when trying to code by voice... (Windows 7, Python 2.7, active keyboard layout: U.S. English)

tylercal commented 9 years ago

What IDE are you using? What happens when you try the command in notepad?

haltuf commented 9 years ago

The problem is not IDE-specific ... same output goes into command line or notepad (except in notepad, ^N is interpreted as CTRL+N and it tries to create new file in the end)

tylercal commented 9 years ago

I'm also using Windows 7, Python 2.7, and the en_us keyboard layout, but that code executes fine for me. Do you get similar results using

(Text("Hello world ") + Key("leftparen,rightparen,space,leftbrace,rightbrace")).execute()
haltuf commented 9 years ago

Yes. Same result with your code.

haltuf commented 9 years ago

I solved the issue - looks like the problem lies in Natlink in the end. Since it can affect anyone, who does not use US keyboard as a primary one, I post a solution here:

The problem lies in the fact, that Natlink detects keyboard layout not based on the CURRENTLY ACTIVE keyboard layout, but using the "Default input language" (Windows 7: Control Panel -> Region and language -> Change keyboard or other input methods -> Change keyboard... and here you can set the Default input language, which has to be en_us)

The other way, how to solve this issue for international (non-US) Windows users, is to add this code to your dragonfly grammar scripts:

import win32api
win32api.LoadKeyboardLayout('00000409',1)

The code must be on the very top of your script (ABOVE dragonfly import).