News:

VC = Vox = VoxCommando
EG = EventGhost
WMC = Windows Media Center
WSR = Windows Speech Recognition

Main Menu

Use Custom buttons addon for Firefox to trigger actions in VC

Started by xtermin8r, April 11, 2013, 04:12:12 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

xtermin8r

Hi everyone

Use Custom buttons addon for firefox to trigger the actions in VoxCommando.

Requirements.
1. VoxCommando. http://voxcommando.com/
2. Mozilla Firefox. Normal version http://www.mozilla.org/en-US/firefox/new/ or
   Mozilla Firefox. Portable version http://portableapps.com/apps/internet/firefox_portable    
3. Custom Buttons Addon for Firefox. https://addons.mozilla.org/en-US/firefox/addon/custom-buttons/

Instructions.  
01. Download and install Mozilla Firefox if you dont have it.
02. Download and install Custom Buttons Addon for Firefox.
03. Click on the firefox tab and select options, Add-on Bar a new tool bar will be added to the bottom of firefox.
04. Right click on the toolbar select Add new button
05. Copy and Paste the code below the Tasmanian Devil into the buttons code section and Click Ok.



/*CODE*/

   var file = Components.classes["@mozilla.org/file/directory_service;1"].
     getService(Components.interfaces.nsIProperties).
     get("ProfD", Components.interfaces.nsIFile); // Profile Directory
   file.append("custombuttons"); // Custom Buttons Directory
   file.append("sendkeys.vbs"); // VBScript File
   var fos = Components.classes["@mozilla.org/network/file-output-stream;1"].
     createInstance(Components.interfaces.nsIFileOutputStream);
   fos.init(file, 0x02|0x08|0x20, parseInt("666", 8), 0);
   // 0x02|0x08|0x20 write, create, truncate
   // 0666 read and write permission for owner, group, others
   var data = "Option Explicit\n" +
     "Dim WshShell\n" +
     'Set WshShell = CreateObject("WScript.Shell")\n' +
     'WshShell.SendKeys"^+s"\n' +
     "Set WshShell = Nothing"; // VBScript Script
   fos.write(data, data.length);
   fos.close();
   var localFile = Components.classes["@mozilla.org/file/local;1"].
     createInstance(Components.interfaces.nsILocalFile);
   localFile.initWithFile(file);
   localFile.launch();


A message box will appear like below The button was successfully created. You can add it to any toolbar via "View -> Toolbars -> Customize…"



06. Click Ok
07. Right click on the toolbar again and select Customise
08. A box will appear like below, scroll down until you see the new button and drag it to the Add-on bar.



09. Click Done
10. Congratulations you have successfully created a button.

the custom button example i have provided uses a vbscript SendKeys method to send keystrokes to applications
the keys used are ctrl + shift + s (^+s) and can be seen in the following line
'WshShell.SendKeys"^+s"\n' +
the above line can be edited to suit your own needs.

11. In order to do something useful we will need to enable the keyboard Hook plugin in VC, so click on Options, then open options, click on the plugins tab, and tick the Hook plugin, then save and close. You may be prompted to do a full restart of VC, if not do it anyway.

12. Next step, from the main screen of VC click on the Plugins tab, Underneath active plugins
you should see Hook, now double click Hook.
You will be presented with a new window called Plugin: Hook, tick log keys, now click on the custom button that you have created, the ctrl + shift + s key will appear as LControlKey+LShiftKey+S, Click on it and it will become highlighted then click on the >> button, this will copy the LControlKey+LShiftKey+S into the specific keys section like below.



13. Click on Save All
14. Once again Click on the Custom button in firefox, now take a look at the Voxcommando History tab you will see the Keystroke like below



15. Now open up the Command editor and then drag and drop the Hook event into an action of your choosing, like below.



16. Save and then close the command editor and restart Voxcommando.
17. Now click on the custom button in firefox once again, if all went well the vc action will be triggered.

Information on the Hook Plugin and Text to Speech is available here http://voxcommando.com/forum/index.php?topic=901.0
Information on Sendkeys is available from here http://msdn.microsoft.com/en-us/library/8c6yea83%28v=vs.84%29.aspx

by using  the Hook Plugin  we are able to trigger any action in Voxcommando  
e.g i use a custom button to trigger the tts engine to speak highlighted text, i have other buttons for home automation etc.



Custom Buttons forum http://custombuttons.sourceforge.net/forum/

If you encounter any problems with this tutorial, please let me know.

Good luck.
Neural Net Based Artificial Intelligence.

xtermin8r

Cloning a button the easy way.

Right Click on a button and select Clone button.
Neural Net Based Artificial Intelligence.

xtermin8r

Neural Net Based Artificial Intelligence.

Kalle

***********  get excited and make things  **********

xtermin8r

Neural Net Based Artificial Intelligence.

jitterjames


jitterjames

This is very cool, but it got me thinking, and I may have come up with something based on this but a little bit better.

This method will hopefully be a bit easier to use, and does not require keyboard shortcuts.  Keyboard shortcuts are OK if you have no other choice, but there are obvious limitations.

I would still use the custom button extension, but I would not use the hook plugin for VC

Instead I suggest trying something like this.

First we will create single button that does not actually do anything but contains a function in the initialization code:

/*CODE*/  

/*Initialization Code*/
sendVC= function(arg) {
      var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile);
      file.initWithPath("J:\\Code\\1 Debug\\voxcommando.exe", "tts.speak&&testing");
      //file.launch();

      var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess);
      process.init(file);

      var args = [arg];
      process.run(false, args, 1);
   }


EDIT: you will need to edit the path to match your VC folder on the line: file.initWithPath("J:\\Code\\1 Debug\\voxcommando.exe", "tts.speak&&testing");

Now we can create as many buttons as we like and the code for them can look something like one of these:

/*CODE*/
sendVC("tts.speak&&testing testing one two three|nice one");


/*CODE*/
sendVC("vc.tellvox&&pay attention");


/*CODE*/
sendVC("event&&testEvent.Thing");

jitterjames

Question for xtermin8r:

do you know if a button can call an URL without actually opening a tab or navigating to the URL?  I assume yes, and I assume you have already figured this out for use with Unimote.  The reason I ask, is that we will soon be able to send command to VC using the same method. (HTTP Get)

xtermin8r

QuoteThis is very cool, but it got me thinking, and I may have come up with something based on this but a little bit better.

This method will hopefully be a bit easier to use, and does not require keyboard shortcuts.  Keyboard shortcuts are OK if you have no other choice, but there are obvious limitations.

I would still use the custom button extension, but I would not use the hook plugin for VC

Instead I suggest trying something like this.

First we will create single button that does not actually do anything but contains a function in the initialization code:

Brilliant stuff James, works fine. Your method is much better, simpler.  I would suggest everyone adopt this new method.:clap

FYI. I dont use the Hook Plugin method myself, but the http url method.
Neural Net Based Artificial Intelligence.

xtermin8r

Quote from: jitterjames on April 13, 2013, 10:47:31 AM
Question for xtermin8r:

do you know if a button can call an URL without actually opening a tab or navigating to the URL?  I assume yes,
Yes.

Quoteand I assume you have already figured this out for use with Unimote.

Correct.

A typical example :

/*CODE*/
var req = new XMLHttpRequest ();
req.open ('GET', 'http://192.168.1.64/vox.cgi?cmd=vc.tellvox&&read%20it', true);
req.send(null);


QuoteThe reason I ask, is that we will soon be able to send command to VC using the same method. (HTTP Get)

Great  :yay.
Neural Net Based Artificial Intelligence.

xtermin8r

Neural Net Based Artificial Intelligence.