Author Topic: Use Custom buttons addon for Firefox to trigger actions in VC  (Read 10167 times)

0 Members and 1 Guest are viewing this topic.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
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: [Select]
/*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.
« Last Edit: April 12, 2013, 09:50:05 AM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #1 on: April 11, 2013, 04:15:23 PM »
Cloning a button the easy way.

Right Click on a button and select Clone button.
« Last Edit: April 11, 2013, 05:56:19 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #2 on: April 11, 2013, 04:15:49 PM »
Reserved
Neural Net Based Artificial Intelligence.

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #3 on: April 11, 2013, 04:25:19 PM »
Nice tutorial  ::bow
***********  get excited and make things  **********

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #4 on: April 11, 2013, 06:31:09 PM »
Neural Net Based Artificial Intelligence.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #5 on: April 11, 2013, 10:26:01 PM »
Excellent  ;D

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #6 on: April 13, 2013, 10:43:25 AM »
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: [Select]
/*CODE*/  
Code: [Select]
/*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:
Code: [Select]
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: [Select]
/*CODE*/
sendVC("tts.speak&&testing testing one two three|nice one");

Code: [Select]
/*CODE*/
sendVC("vc.tellvox&&pay attention");

Code: [Select]
/*CODE*/
sendVC("event&&testEvent.Thing");
« Last Edit: April 13, 2013, 10:45:41 AM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #7 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, 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

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #8 on: April 13, 2013, 01:42:10 PM »
Quote
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:

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.
« Last Edit: April 13, 2013, 02:01:42 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #9 on: April 13, 2013, 01:53:04 PM »
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.

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

Correct.

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

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

Great  :yay.
« Last Edit: April 13, 2013, 02:11:25 PM by xtermin8r »
Neural Net Based Artificial Intelligence.

xtermin8r

  • $upporter
  • Sr. Member
  • *****
  • Posts: 366
  • Karma: 9
  • Crunchie
    • View Profile
Re: Use Custom buttons addon for Firefox to trigger actions in VC
« Reply #10 on: May 11, 2013, 02:21:37 PM »
Hi

My new Custom Buttons Navigation Menu.

Neural Net Based Artificial Intelligence.