Cyborgscode / Personal-Voice-Assistent

Building a fully featured and localized voice assistant for Linux
141 stars 6 forks source link

Request: Integrate keyboard shortcut support to PVA? #11

Closed raithel closed 1 year ago

raithel commented 1 year ago

I would like to propose looking into the possibility to integrating keyboard shortcut support into PVA.

This would allow for you to tie many user based interactions to voice commands.

I have already implemented this on my personal machine. ;)

I use this feature all of the time when I am working on one computer, and reading documentation or an article on my personal computer and need hands free navigation.

This would allow for opening the door to many window manager agnostic accessibility features using PVA.

Currently the way I have this implemented on my install, is a modification to pva.java and the 01-default.conf file:

Here are some examples that I am already using on my personal install of PVA:

Section of pva.java

// start apps by name

                                if ( cf.command.equals("OPENSOURCECODE") ) {
                                        exec( (config.get("app","txt") + " ./PVA.java").split(" ") );
                                        say( texte.get( config.get("conf","lang_short"), "OPENSOURCECODE") );
                                }
                                if ( cf.command.equals("OPENCONFIG") ) {
                                        exec( (config.get("app","txt") +" "+ getHome() +"/.config/pva/pva.conf").split(" ") );
                                        say( texte.get( config.get("conf","lang_short"), "OPENCONFIG") );
                                }

                                //Action related commands. 
                                if ( cf.command.equals("PAGEDOWN") ) {
                                        exec( config.get("app","pgdwn") );
                                        say( texte.get( config.get("conf","lang_short"), "PAGEDOWN") );
                                }
                                if ( cf.command.equals("PAGEUP") ) {
                                        exec( config.get("app","pgup") );
                                        say( texte.get( config.get("conf","lang_short"), "PAGEUP") );
                                }
                                if ( cf.command.equals("PRESSHOME") ) {
                                        exec( config.get("app","presshome") );
                                        say( texte.get( config.get("conf","lang_short"), "PRESSHOME") );
                                }
                                if ( cf.command.equals("PRESSEND") ) {
                                        exec( config.get("app","pressend") );
                                        say( texte.get( config.get("conf","lang_short"), "PRESSEND") );
                                }
                                if ( cf.command.equals("MAXIMIZEWINDOW") ) {
                                        exec( config.get("app","maximizewindow") );
                                        say( texte.get( config.get("conf","lang_short"), "MAXIMIZEWINDOW") );
                                }
                                if ( cf.command.equals("MINIMIZEWINDOW") ) {
                                        exec( config.get("app","minimizewindow") );
                                        say( texte.get( config.get("conf","lang_short"), "MINIMIZEWINDOW") );
                                }

relevant sections of 01-default.conf

### Added apps:
app:"pgup","xdotool key Page_Up"
app:"pgdwn","xdotool key Page_Down"
app:"pressend","xdotool key ctrl+End"
app:"presshome","xdotool key ctrl+Home"
app:"maximizewindow","xdotool key ctrl+Super+Up"
app:"minimizewindow","xdotool key Shift+Alt+Page_Down"

### === ACTIONS === ###
text:"en","PRESSHOME","Jumping to top."
text:"en","PRESSEND","Jumping to end."

text:"en","PAGEUP","Scrolling page up."
text:"en","PAGEDOWN","Scrolling page down."

text:"en","MAXIMIZEWINDOW","maximizing."
text:"en","MINIMIZEWINDOW","minimizing."

### Action commands:
command:"page up","PAGEUP",""
command:"page down","PAGEDOWN",""

command:"go|to|top","PRESSHOME",""
command:"go|to|bottom","PRESSEND",""
command:"go|to|end","PRESSEND",""

command:"maximize|window","MAXIMIZEWINDOW",""
command:"minimize|window","MINIMIZEWINDOW",""

Currently I have integrated keyboard shortcuts into PVA by adding app commands in the config using the xdotool command. I realize that this has the possibility of adding yet another dependency to PVA, but I believe that the functionality that it adds could be well worth it.

The xdotool command is a small utility that allows for automation of keyboard and mouse input using scripts. To my knowledge it is available on most all Linux Distros using the default package managers. (apt, dnf, pacman, pkg, zypper, brew, etc...)

Allowing for keyboard shortcut support would allow for PVA to work with any window manager in a platform agnostic manner. No need to mess with window manager specific APIs. ;)

Thus you would be able to link many window manager actions to the keyboard shortcuts that are already in place. :)

This would allow for you to perform interface based actions with PVA using minimal configuration changes on any window manager that supports keyboard shortcuts.

Please let me know if you have any questions, or suggestions on any better ways to implement this kind of functionality.

As mentioned, if you have any questions for me, please feel free to contact me. Thank you for your time and considerations!

Cyborgscode commented 1 year ago

Notice:

Upcoming NetFlix Plugin allows control via event simulation for Netflix UI, but the scheme can be reused in a general keyboard&mouse simulation plugin.

Cyborgscode commented 1 year ago

btw. you can already make this work by using EXEC: functionality added in 2022

command:"page up","EXEC:xdotoolx:xkeyx:xPage_Up" command:"page down","EXEC:xdotoolx:xkeyx:xPage_Down" etc.

Cyborgscode commented 1 year ago

Please see netflix plugin code & config for scripts and usefull codes.

New functionality should come from plugins, as anyone can later decide if a given functionality shall be part of his instance or not.

Cyborgscode commented 1 year ago

command:"pgup","EXEC:xdotoolx:xkeyx:xPage_Up" command:"pgdwn","EXEC:xdotoolx:xkeyx:xPage_Down" command:"pressend","EXEC:xdotoolx:xkeyx:xctrl+End" command:"presshome","EXEC:xdotoolx:xkeyx:xctrl+Home" command:"maximizewindow","EXEC:xdotoolx:xkeyx:xctrl+Super+Up" command:"minimizewindow","EXEC:xdotoolx:xkeyx:xShift+Alt+Page_Down"