Topics

Invoking keystrokes through add-on code


Jacob Kruger
 

Hi there


I might want to get an add-on to execute sets of keystrokes, possibly including some that are NVDA specific one after another, at set time intervals?


I have pyautogui installed here, and, from normal python code, I can use something along the lines of pyautogui.hotkey("ctrl", "a")#just an example - to pass a keystroke through to operating system, but, for example, if I invoke NVDA python console, and ask it to import pyautogui, it tells me 'module not found'?


As in, should this module be placed in a specific location relative to path of add-on's own code, or in relation to NVDA for now, or else, is there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."


James Scholes
 

import inputCore
import keyboardHandler
gesture = keyboardHandler.KeyboardInputGesture.fromName('control+v')
inputCore.manager.emulateGesture(gesture)

Regards,

James Scholes

On 05/01/2021 at 5:17 am, Jacob Kruger wrote:
Hi there


I might want to get an add-on to execute sets of keystrokes, possibly including some that are NVDA specific one after another, at set time intervals?


I have pyautogui installed here, and, from normal python code, I can use something along the lines of pyautogui.hotkey("ctrl", "a")#just an example - to pass a keystroke through to operating system, but, for example, if I invoke NVDA python console, and ask it to import pyautogui, it tells me 'module not found'?


As in, should this module be placed in a specific location relative to path of add-on's own code, or in relation to NVDA for now, or else, is there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."


Jacob Kruger
 

Thanks, James, just tested that in the python console, and, worked perfectly.


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."

On 2021-01-05 07:24 PM, James Scholes wrote:
import inputCore
import keyboardHandler
gesture = keyboardHandler.KeyboardInputGesture.fromName('control+v')
inputCore.manager.emulateGesture(gesture)

Regards,

James Scholes

On 05/01/2021 at 5:17 am, Jacob Kruger wrote:
Hi there


I might want to get an add-on to execute sets of keystrokes, possibly including some that are NVDA specific one after another, at set time intervals?


I have pyautogui installed here, and, from normal python code, I can use something along the lines of pyautogui.hotkey("ctrl", "a")#just an example - to pass a keystroke through to operating system, but, for example, if I invoke NVDA python console, and ask it to import pyautogui, it tells me 'module not found'?


As in, should this module be placed in a specific location relative to path of add-on's own code, or in relation to NVDA for now, or else, is there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."






Noelia Ruiz
 

I was also testing to reply. For set an interval, I tested this code
with success:

gesture = KeyboardInputGesture.fromName("NVDA+t")
core.callLater(200, gesture.send)

See documentation of core.callLater( for limitations.

Cheers

2021-01-05 19:22 GMT+01:00, Jacob Kruger <jacob@blindza.co.za>:

Thanks, James, just tested that in the python console, and, worked
perfectly.


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."
On 2021-01-05 07:24 PM, James Scholes wrote:
import inputCore
import keyboardHandler
gesture = keyboardHandler.KeyboardInputGesture.fromName('control+v')
inputCore.manager.emulateGesture(gesture)

Regards,

James Scholes

On 05/01/2021 at 5:17 am, Jacob Kruger wrote:
Hi there


I might want to get an add-on to execute sets of keystrokes, possibly
including some that are NVDA specific one after another, at set time
intervals?


I have pyautogui installed here, and, from normal python code, I can use
something along the lines of pyautogui.hotkey("ctrl", "a")#just an
example - to pass a keystroke through to operating system, but, for
example, if I invoke NVDA python console, and ask it to import pyautogui,
it tells me 'module not found'?


As in, should this module be placed in a specific location relative to
path of add-on's own code, or in relation to NVDA for now, or else, is
there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat
experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."







James Scholes
 

To provide some additional context: if using the emulateGesture method on inputCore.manager, NVDA will first attempt to fire the gesture internally, meaning that any scripts bound to it will also be executed. For example:

inputCore.manager.emulateGesture(keyboardHandler.KeyboardInputGesture.fromName('nvda+1'))

Assuming default settings, executing the above in the Python Console will toggle on input help mode, and you'll need to press NVDA+1 again to turn it off. But if you run:

keyboardHandler.KeyboardInputGesture.fromName('nvda+1').send()

... the character "1" will be typed instead, because the gesture is passed through to Windows. As a final example though, if you execute:

inputCore.manager.emulateGesture(keyboardHandler.KeyboardInputGesture.fromName('nvda+0'))

... the character "0" will be typed, because by default no script is bound to NVDA+0 so the emulateGesture method performs a passthrough. You can hence determine which method is best for your application:

1. If you want to truly emulate a user action, use inputCore.manager.emulateGesture. This will execute a keystroke which may or may not be bound to an NVDA script, have that script be executed if it exists or the key passed through to Windows if it doesn't.
2. If you want to bypass NVDA altogether as though you'd pressed NVDA+F2, and just send the keystroke through to the operating system, use the send method on your created gesture.

Regards,

James Scholes

On 05/01/2021 at 1:25 pm, Noelia Ruiz wrote:
I was also testing to reply. For set an interval, I tested this code
with success:

gesture = KeyboardInputGesture.fromName("NVDA+t")
core.callLater(200, gesture.send)

See documentation of core.callLater( for limitations.

Cheers

2021-01-05 19:22 GMT+01:00, Jacob Kruger <jacob@blindza.co.za>:
Thanks, James, just tested that in the python console, and, worked
perfectly.


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."
On 2021-01-05 07:24 PM, James Scholes wrote:
import inputCore
import keyboardHandler
gesture = keyboardHandler.KeyboardInputGesture.fromName('control+v')
inputCore.manager.emulateGesture(gesture)

Regards,

James Scholes

On 05/01/2021 at 5:17 am, Jacob Kruger wrote:
Hi there


I might want to get an add-on to execute sets of keystrokes, possibly
including some that are NVDA specific one after another, at set time
intervals?


I have pyautogui installed here, and, from normal python code, I can use
something along the lines of pyautogui.hotkey("ctrl", "a")#just an
example - to pass a keystroke through to operating system, but, for
example, if I invoke NVDA python console, and ask it to import pyautogui,
it tells me 'module not found'?


As in, should this module be placed in a specific location relative to
path of add-on's own code, or in relation to NVDA for now, or else, is
there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat
experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."










Sean
 

You need to copy the module and your plugin system to the strachpath directory.

On 05/01/2021 14:17, Jacob Kruger wrote:

Hi there


I might want to get an add-on to execute sets of keystrokes, possibly including some that are NVDA specific one after another, at set time intervals?


I have pyautogui installed here, and, from normal python code, I can use something along the lines of pyautogui.hotkey("ctrl", "a")#just an example - to pass a keystroke through to operating system, but, for example, if I invoke NVDA python console, and ask it to import pyautogui, it tells me 'module not found'?


As in, should this module be placed in a specific location relative to path of add-on's own code, or in relation to NVDA for now, or else, is there some other module I should work with in this context instead?


And, yes, at this stage, this relates to a more or less somewhat experimental concept, but anyway.


TIA


Jacob Kruger
+2782 413 4791
Skype: BlindZA
"...resistance is futile...but, acceptance is versatile..."