StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
 All Forums
 General Discussion
 General Discussion
 How to send hotkey to Firefox when Flash has focus

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Cerberus Posted - 05/05/2012 : 03:14:40
When I have my gesture open a new tab in Firefox (control-t), this doesn't work when a Flash object has focus, like a Youtube video. All hotkeys go to Flash, not to the actual page or to the Firefox interface, and nothing happens. Do you know of any way to circumvent this? Any suggestion, work-around, or external application is welcome!

---------------------------------------------------------------
The only thing you can do is click on the address bar, then tab, then control-t, because that takes away focus from Flash. I have an Autohotkey script that does this.

However, I don't like it, because it is slow and sometimes unreliable. So I don't want my New Tab gesture to always cause Autohotkey to click the address bar, but only when Flash has focus (or any other plugin object). I have created a separate application in S+ called "Flash" that uses the identifier plugin-container.exe. All gestures in this application, like N for New Tab, send a special hotkey (like alt-control-shift-q) to Autohotkey; and Autohotkey in turn translates this into a mouse click on the address bar, tab, and control-t.

But this only works if the starting point of my gesture is above the Flash element (like the Youtube video). If Flash has focus, but I start my gesture elsewhere on the page, such as to the right of the video, S+ thinks I am in Firefox, and it carries out the action as set up there, even though focus is still on Flash. That action is just control-t, which is unable to take back focus from Flash, so nothing happens.

Am I forgetting something? Do you have any idea how I can fix this? Is there anything I can do within S+? Any help is appreciated.
20   L A T E S T    R E P L I E S    (Newest First)
noice Posted - 03/01/2016 : 14:29:42
Thanks for the addon!
For the lazy, here's the updated addon ready: http://s000.tinyupload.com/index.php?file_id=92528631104816356926
(credit goes to Udon, I just put his code into files)
Udon Posted - 01/31/2016 : 17:10:36
quote:
Originally posted by Cerberus

I will try to keep at least the version number up to date, because Mozilla forced me to set the maximum version of Firefox that it can be installed on to 46.0. But, if the extension should break otherwise, I wouldn't know how to fix it...




I'm very glad that the extension is used and works well. I use some other mouse gesture program now, but the extension is the same and works well locally.

Well, the extension I'm using is not exactly the same. Mozilla released multiprocess versions of Firefox lately (as of now, enabled by default in developer and nightly versions). They release stable multiprocess versions from version 46. The date is 2016-04-19. In multiprocess Firefox, both extensions I posted here and you posed in addons.mozilla.org will not work. I post the revised one below, which works in single/multi-process Firefox and is bootstrapped (restartless). I'm using it on Firefox version 46 with multiprocess enabled.

On 64-bit versions (from 44), whose stable versions are not released yet, the extension (both old and revised) does not work well. Mouse events over Flash Player are not detected by Firefox. It's a bug and reported in Bugzilla@Mozilla (Bug 1234958).

You need not modify any configuration on StrokesPlus.

There are only three files(bootstrap.js, frameScript.js and install.rdf) and no subdirectory structures. install.rdf is based on your posted one.


install.rdf
added: bootstrap and multiprocessCompatible properties
modified: versions (three places)
removed: description (embedded code is not wrapped)
<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">

  <Description about="urn:mozilla:install-manifest">

    <em:id>sanuki.udon@kagawa</em:id>
    <em:version>2.0</em:version>
    <em:type>2</em:type>
    <em:bootstrap>true</em:bootstrap>
    <em:multiprocessCompatible>true</em:multiprocessCompatible>

    <!-- Target Application this extension can install into,
         with minimum and maximum supported versions. -->
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>44.0</em:minVersion>
        <em:maxVersion>47.0</em:maxVersion>
      </Description>
    </em:targetApplication>

    <!-- Front End MetaData -->
    <em:name>Get Back Focus from Plugin</em:name>
    <em:description>
      <![CDATA[
      ]]>
    </em:description>
    <em:creator>Sanuki Udon</em:creator>

  </Description>

</RDF>


bootstrap.js
const {
  classes: Cc,
  interfaces: Ci,
  manager: Cm,
  results: Cr,
  utils: Cu
} = Components;

Cu.import("resource://gre/modules/Services.jsm");

const SHUTDOWN_MSG = "GetBackFocusFromPlugin:Shutdown";

const DATA_URI_PREFIX = "data:,Components.utils.import('";
const DATA_URI_SUFFIX = "');init(this);";

let path = __SCRIPT_URI_SPEC__.replace("bootstrap.js", "frameScript.js");
let url = path + "?" + Math.random();
let dataURI = DATA_URI_PREFIX + url + DATA_URI_SUFFIX;

function startup(aData, aReason) {

  Services.mm.loadFrameScript(dataURI, true);

}

function shutdown(aData, aReason) {

  if (aReason == APP_SHUTDOWN) {
    return;
  }

  Services.mm.removeDelayedFrameScript(dataURI);
  Services.mm.broadcastAsyncMessage(SHUTDOWN_MSG);

}

function install(aData, aReason) {}
function uninstall(aData, aReason) {}


frameScript.js
const EXPORTED_SYMBOLS = ["init"];

const {
  classes: Cc,
  interfaces: Ci,
  manager: Cm,
  results: Cr,
  utils: Cu
} = Components;

Cu.import("resource://gre/modules/Services.jsm");

const SHUTDOWN_MSG = "GetBackFocusFromPlugin:Shutdown";

function wheelListener(aEvent) {

  if (1.0 > aEvent.deltaY && aEvent.deltaY > 0.0
  ||  0.0 > aEvent.deltaY && aEvent.deltaY > -1.0) {
    aEvent.stopPropagation();
  } else {
    return;
  }

  if (1.0 > aEvent.deltaY && aEvent.deltaY > 0.0) {

    let focusedWindow = {};
    let focusedElement = Services.focus
      .getFocusedElementForWindow(this.content, true, focusedWindow);

    focusedWindow = focusedWindow.value;

    if (focusedElement && focusedElement.hasRunningPlugin) {
      Services.focus.clearFocus(focusedWindow);
    }
    Services.focus.focusedWindow = focusedWindow;

  }

}

function shutdownListener(aMessage) {
  uninit(this);
}

function unloadListener(aEvent) {
  uninit(this);
}

function init(aScope) {
  aScope.addEventListener("wheel", wheelListener, true);
  aScope.addEventListener("unload", unloadListener);
  aScope.addMessageListener(SHUTDOWN_MSG, shutdownListener);
}

function uninit(aScope) {
  aScope.removeEventListener("wheel", wheelListener, true);
  aScope.removeEventListener("unload", unloadListener);
  aScope.removeMessageListener(SHUTDOWN_MSG, shutdownListener);
}

Cerberus Posted - 01/18/2016 : 21:31:15
Dear Udon, somehow I only saw your brilliant suggestion recently. I have created the XPI file and the function in Strokes Plus, and it works very well. I don't know whether you will see this message, but thank you very much! I have taken the liberty of uploading the extension on Mozilla.org in order that all may benefit from your solution without having to create the XPI file themselves:

https://addons.mozilla.org/en-GB/firefox/addon/get-back-focus-from-plugin/

I will try to keep at least the version number up to date, because Mozilla forced me to set the maximum version of Firefox that it can be installed on to 46.0. But, if the extension should break otherwise, I wouldn't know how to fix it...

P.S. Hi Rob! It's been a while! I'm still a very happy stroker, though.
Strokeman Posted - 05/14/2015 : 11:29:07
Haven't tried the Xpi extension solution but above doesn't work or me
Opens up some right context menu etc (was using for closing tab)

(Used on Win XP, X64 bit, FFox v35)

poweruser84 Posted - 02/10/2015 : 15:26:12
Here is a working solution for Firefox and Opera browsers. No extensions needed.

Successfully tested in:
1) Firefox
2) Opera 12 (and earlier Presto-based versions).

An example of the gesture that opens a new tab in Firefox (or closes the current tab etc.) in a case when a Flash object has focus:

local tx = acGetWindowRight(nil, gsx, gsy)
local ty = acGetWindowTop(nil, gsx, gsy)
local tcy = acGetWindowBottom(nil, gsx, gsy)
acMouseClick(tx-35, (tcy-ty)-((tcy-ty)/2), 0, 1, 1)
acDelay(300)
acSendKeys("{ESC}")
acDelay(100)
acSendKeys("^t")
acMouseMove(gex, gey)


Firefox. The gesture should be added to:
- firefox.exe application context (firefox.exe, Control Class Name: MozillaWindowClass)
- Flash plugin context in Firefox (Control Class Name: GeckoPluginWindow)


For Opera 12 (and earlier) the gesture should be added to :
- opera.exe context - opera.exe / OperaWindowClass (Control Class Name)
- Flash plugin context in Opera (Control Class Name = aPluginWinClass - for Opera x86; Control Class Name = PluginWrapperWindow - for Opera x64 build)



Try it!
Udon Posted - 11/26/2014 : 09:04:27

quote:

hello,
I followed your instructions but it didn't work on my firefox 33.1.1 on windows8.1x64 , nothing happened.



I modified the post above a bit. But I tested the previous version before this post and it worked. I don't know what happened on your environment. The add-on was installed? Or That failed? If it was installed and it did not worked, did you see any error messages in the Browser Console? For example, put the line in the getBackFocusFromPlugin.js

console.log("deltaY: " + aEvent.deltaY);

just as in my post above.

On my environment(Firefox 34, Windows 7 x64), the output lines are like this:

"deltaY: 0.025"
"deltaY: -0.025"

They are caused by the acPostMessage method of StrokesPlus in the post. On usual scrolls,

"deltaY: 3"
"deltaY: -3"

appears.

In your Configure Actions panel of StrokesPlus, do you include "Flash Player" in File Name Pattern field? On my StrokesPlus, the field is:

firefox\.exe|FlashPlayerPlugin\w+\.exe

nuance Posted - 11/25/2014 : 03:29:44
quote:
Originally posted by Udon

For Firefox Users:
.................................................
..................................................
[/blue][/code]


hello,
I followed your instructions but it didn't work on my firefox 33.1.1 on windows8.1x64 , nothing happened.
Udon Posted - 07/05/2014 : 13:42:19
For Firefox Users:

Firefox receives mouse wheel events even if it has lost focus or these events are fired over plugins. You can take advantage of the fact and get Firefox to get back focus from plugins. The story goes like this.

(1) StrokesPlus sends a mouse wheel message with very small delta to Firefox.
(2) A Firefox add-on catches the massage and clear the current plugin focus.
(3) StrokesPlus sends any target message.
(4) Firefox catches the message safely.

(3) and (4) don't need any extra work. (4) is automatically achieved by (2).

(1): Define the following global Lua function.

function firefox_before_action(x, y)

  local hwndTarget = acGetWindowByPoint(x, y)
  local MessageID  = 0x020A -- WM_MOUSEWHEEL
  local wParamDown = 0xFFFF0000 -- WHEEL_DELTA
  local wParamUp   = 0x00010000 -- WHEEL_DELTA
  local lParam     = bit32.lshift(y,16)+x  -- pointer position

  acPostMessage(hwndTarget, MessageID, wParamDown, lParam) -- caught by Firefox
  acPostMessage(hwndTarget, MessageID, wParamUp, lParam)   -- negate the scroll above
  acSendKeys("%{F16}")  -- hide popup menus by the Alt key (F16 is a dummy key)

end

And call it first in Lua scripts like this.

firefox_before_action(gsx, gsy)  -- Call First
acSendKeys("^{TAB}") -- Next Tab


(2): This is a bit demanding. You should create your own add-on from scratch. One example is as follows.

First, create the following file structure in your working folder.

(working folder):
install.rdf
chrome.manifest
/chrome/content/getBackFocusFromPlugin.xul
                getBackFocusFromPlugin.js

The content/code of each file is given below. Then, zip all the contents in your working folder. (Do not zip the working folder. Select all the contents and zip them.) Change the extension(.zip) of the zip file to ".xpi". Your add-on is finally created. To install it, drag and drop the "xpi" file on a main window of Firefox. (Firefox doesn't care about the base filename, so you can change it such as "getBackFocusFromPlugin.xpi".)

install.rdf
(Put <?xml version="1.0"?> at the first position of the first line.)

<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
  
  <Description about="urn:mozilla:install-manifest">
  
    <em:id>sanuki.udon@kagawa</em:id>
    <em:version>1.0</em:version>
    <em:type>2</em:type>
    
    <!-- Target Application this extension can install into, 
         with minimum and maximum supported versions. --> 
    <em:targetApplication>
      <Description>
        <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
        <em:minVersion>0</em:minVersion>
        <em:maxVersion>99</em:maxVersion>
      </Description>
    </em:targetApplication>
    
    <!-- Front End MetaData -->
    <em:name>Get Back Focus from Plugin</em:name>
    <em:description>
      <![CDATA[
This Add-on gets back focus from plugins.
      ]]>
    </em:description>
    <em:creator>Sanuki Udon</em:creator>
    
  </Description>
  
</RDF>


chrome.manifest

content getBackFocusFromPlugin chrome/content/
overlay chrome://browser/content/browser.xul chrome://getBackFocusFromPlugin/content/getBackFocusFromPlugin.xul



getBackFocusFromPlugin.xul
(Put <?xml version="1.0"?> at the first position of the first line.)

<?xml version="1.0"?>

<overlay id="getBackFocusFromPlugin"
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  
  <script type="application/x-javascript" src="chrome://getBackFocusFromPlugin/content/getBackFocusFromPlugin.js" />
  
</overlay>



getBackFocusFromPlugin.js

Components.utils.import("resource://gre/modules/Services.jsm");

window.addEventListener("wheel", function(aEvent) {

  // console.log("deltaY: " + aEvent.deltaY);
  if ( ( 1.0 > aEvent.deltaY ) && ( aEvent.deltaY > 0.0 ) ) {

    var focusedElement = Services.focus.focusedElement;
    var focusedWindow = focusedElement ? Services.focus.focusedWindow : content;

    if (focusedWindow == window) {
      Services.focus.clearFocus(focusedWindow);
      Services.focus.setFocus(focusedElement, Services.focus.FLAG_NOSCROLL);
    } else {
      Services.focus.focusedWindow = window;
      if (focusedElement && focusedElement.hasRunningPlugin) {
        Services.focus.clearFocus(focusedWindow);
      }
      Services.focus.focusedWindow = focusedWindow;
    }

  }

});
Strokeman Posted - 07/03/2014 : 05:32:44
I was researching more and a bit intriguing is the fact that some gestures like maximize window/restore window work nicely without any issues, when at the same time some gestures like Close Tab or Close Window don't work, on such flash related sites like Youtube
Further another confusing thing is if we press the Keyboard shortcut manually of the gestures not working, they work fine, in above instances.
I even enabled "Play Sound on mismatch" and ensured that i am drawing proper gestures (just to be sure)

Strokeman Posted - 07/02/2014 : 08:52:01
quote:


local tx = acGetWindowLeft(nil, gsx, gsy)
local ty = acGetWindowTop(nil, gsx, gsy)
local tcy = acGetWindowBottom(nil, gsx, gsy)
acMouseClick(tx+8, (tcy-ty)-((tcy-ty)/2), 2, 1, 1)
acMouseMove(gex, gey)
acSendKeys("^t")

Of course, if there happens to be an ad or link in that spot, it'll click it; but I doubt that would happen often, if ever.



Rob, as i posted before, i am suffering from same issue and probably the reason why i get missed gesture strokes many times. (Sometimes, i see FFox window not active, even when i am on FF window itself. After Clicking on top FF bar fixes it. But sometimes nothing works). Regarding the above solution 3 questions:
1)Does that mean we have to add this code in almost all gestures of browser?
2) If no, do we need to add this as some global lua code? if yes, how to do so & will it add lag?
3)I see "Cerberus" has a point . Is there any way we can make S+ run this code only when flash is in play? (ofc without matching titles,etc as its no logical to code for each website having such players)

Thanks for your time
Regards
Strokeman Posted - 06/28/2014 : 14:29:03
Me too having good amount of issues with flash websites like youtube
Gestures just dont work when such websites are running on firefox, whereas strokeplus works fine at same time on other tabs

Any solution for it guys?
Does really right clicking and empty area and then gesturing solve the issue?
i tried but didn't help

Thanks

poweruser84 Posted - 06/22/2014 : 08:00:01
I've found that using browser's context menu (right click) to take away focus from the plugin content area is a way better solution. Because it not causing conflict with browser's side bar panel (Firefox with All-In Ine Sidebar extension or Opera/Presto).

Firefox

New application.
Control Class Name: GeckoPluginWindow

Code:
local tx = acGetWindowRight(nil, gsx, gsy)
local ty = acGetWindowTop(nil, gsx, gsy)
local tcy = acGetWindowBottom(nil, gsx, gsy)
acMouseClick(tx-35, (tcy-ty)-((tcy-ty)/2), 0, 1, 1)
acDelay(200)
acSendKeys("{ESC}")
acDelay(100)
acSendKeys("{ESC}")
acDelay(100)
acSendKeys("^w")
acMouseMove(gex, gey)


Opera 12.xx (Presto) and older:

New application.
Control Class Name: PluginWrapperWindow (for Opera x64)
Control Class Name: aPluginWinClass (for Opera x86, 32-bit build)

Code:
local tx = acGetWindowRight(nil, gsx, gsy)
local ty = acGetWindowTop(nil, gsx, gsy)
local tcy = acGetWindowBottom(nil, gsx, gsy)
acMouseClick(tx-35, (tcy-ty)-((tcy-ty)/2), 0, 1, 1)
acDelay(100)
acSendKeys("{ESC}")
acDelay(100)
acSendKeys("{ESC}")
acDelay(100)
acSendKeys("^w")
acMouseMove(gex, gey)




jingkun Posted - 11/07/2013 : 11:18:43
It will work better if we mimic a click in the searchBar instead of a click in the middle of the window. SearchBar is fixed to the right-top corner of Firefox window.


local txLeft = acGetWindowLeft(nil, gsx, gsy)
local txRight = acGetWindowRight(nil, gsx, gsy)
local tyTop = acGetWindowTop(nil, gsx, gsy)
local tyBottom = acGetWindowBottom(nil, gsx, gsy)

acMouseClick(txRight-148, tyTop +100, 2, 1, 1)

acSendKeys("{BROWSERBACK}")

acMouseMove(gex, gey)
Cerberus Posted - 06/17/2012 : 00:02:39
Thanks! It's really nice of you to write that script. I think I will stay with my AHK script for now, because I have it activate only when a plugin is present, and having it always active would cause a general slow-down for each and every gesture, which I'd rather not have. Unless S+ is way, way quicker with its script than Autohotkey, but I doubt whether that is possible, what with the mouse move and all. Oh, and I have it click on the address bar, which is always safe.
Rob Posted - 06/16/2012 : 23:50:05
Made a small correction in the code above.
Rob Posted - 06/16/2012 : 23:44:52
I've looked at it again and the only solution I can come up is synthesizing a click to take focus away from the plug-in; apparently this is a known Firefox complaint.

For the most part, it would generally be safe to click in the middle of the window, to the far left, just inside the FF border, send the click, send Ctrl+T and move the mouse back to gesture end location..it works..though depending on your window border sizes, whether FF is maximized or not, etc., you'll have to mess with the tx+8 in the acMouseClick call, adjusting to get the left-most location just inside the HTML area. You can comment out the acMouseMove action call to see where the mouse is trying to send the click to fine tune the placement. But other than that, there's really nothing I can think of; it's in Mozilla's hands.

local tx = acGetWindowLeft(nil, gsx, gsy)
local ty = acGetWindowTop(nil, gsx, gsy)
local tcy = acGetWindowBottom(nil, gsx, gsy)
acMouseClick(tx+8, (tcy-ty)-((tcy-ty)/2), 2, 1, 1)
acMouseMove(gex, gey)
acSendKeys("^t")

Of course, if there happens to be an ad or link in that spot, it'll click it; but I doubt that would happen often, if ever.
Cerberus Posted - 06/16/2012 : 23:02:00
You didn't happen to find any solution to this problem by accident, did you? Because I think it cannot be fixed. Autohotkey can see detect when *some* Flash controls are activated, notably Youtube, but many other it cannot distinguish from the rest of the browsing area in FF.

I have created a Greasemonkey script that tries to detect when a page contains a Flash control, thereupon adds [Plugin] to the title of the tab/window; then I use Autohotkey to only do the mouse clicks if that is present in the title (otherwise it would slow down actions even when there is no need). This works fairly well, except that it is so far not possible for me to detect all Flash controls with the Greasemonkey script: some pages slip through. I don't know of a reliable way to catch them all.
Rob Posted - 05/05/2012 : 12:43:48
It doesn't have anything to do with activating at mouse cursor location as that's exactly what acActivateWindow(nil,gsx, gsy) would emulate.

I used Spy++ to see what's going on and it's tricky; my theory about the other window by the plug-in doesn't appear to be the real issue here. At this point, the only logical conclusion is the Firefox itself is maintaining the state of whether the plug-in has been interacted with, and if the focus has not left the control, Firefox doesn't process its normal accelerator keys. This makes sense as many plug-ins may *want* to have CTRL+T do something and FF shouldn't stand in the way.

I've tried many direct messages to make FF think I've activated the parent window, but it won't be fooled =P The only thing I can think of at this point is to write a script which sends a mouse click to perhaps to somewhere in the furthest corner of the page and move the mouse back to where it was, then send CTRL+T. That's not a very reliable method, but so far it's not looking good =/

I'm heading out for a while, but will keep trying to figure out a solid/consistent approach (I enjoy the challenge) later today or tomorrow.
Cerberus Posted - 05/05/2012 : 04:56:56
Hi! Yes, I tried acActivateWindow(nil,gsx, gsy), and I have tried it again just now, but it doesn't appear to help at all, alas.

The strange thing is that the action in my "Youtube" application is triggered when I start the gesture from inside the video, regardless of whether the video has focus.

But, if the video has focus while I start the gesture outside the video, S+ thinks I am in "Firefox", so the simple control-t action is performed, which has no effect, because the video still has focus.

If the video does not have focus and I start from outside the video, it is recognized as "Firefox", which is correct in this case, and control-t works as intended.

Not sure why I am repeating this, perhaps for clarity. It's not S+'s fault at all, mind you; it's Adobe's and/or Mozilla's fault, grrrr. I was just hoping S+ might have a (partial) solution or work-around.

[Edit:] It may have something to do with Beholden's question about activating the window that the cursor is on at the start of the gesture.
Rob Posted - 05/05/2012 : 03:58:31
While I'll look into a better solution (script), have you tried an activate call (probably would only work when starting the drawing outside of the plug-in area):

acActivateWindow(nil,gsx, gsy)
(then your existing script)

In theory, it should activate FF and the keys be accepted. The biggest problem is that the plug-in container is a completely different application, being told to render where FF is telling it to, but under the hood, it's really two separate programs. Chrome doesn't handle it this way and I don't have any issues, so I seldom get into FF to see how things work there.

As I said, I'll see if there's anything else than can be done. Though I would imagine it may involve finding the FF window and activating directly, then sending the keys, or finding the FF window and directly posting the key message.

StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000