Simulate ctrl+shift+v and f

General discussion about Custom Buttons, including feature requests.

Simulate ctrl+shift+v and f

Postby niceboy76 » Fri Aug 18, 2017 11:37 pm

Hello everybody,

I need two buttons, the first for simulate ctrl+shift+v and a second for simulate ctrl+shift+f (it's for opening different options in Adblock Latitude in Palemoon).

For your information, I have this code for simulate ctrl+shift+F3 (for element to hide in ABP/ABL)

Code: Select all
/*Code*/
// simulate ctrl+shift+f3
var utils = document.commandDispatcher.focusedWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendKeyEvent("keypress", KeyEvent.DOM_VK_F3, 0,
  Event.CONTROL_MASK | Event.SHIFT_MASK);


Thanks in advance for your answer.

Have a nice weekend.
niceboy76
 
Posts: 15
Joined: Sun Feb 23, 2014 5:34 am

Re: Simulate ctrl+shift+v and f

Postby morat » Sat Aug 19, 2017 2:21 am

Try these:

Code: Select all
/*Code*/
// simulate ctrl+shift+v
var utils = document.commandDispatcher.focusedWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendKeyEvent("keypress", 0, KeyEvent.DOM_VK_V,
  Event.CONTROL_MASK | Event.SHIFT_MASK);

Code: Select all
/*Code*/
// simulate ctrl+shift+f
var utils = document.commandDispatcher.focusedWindow.
  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendKeyEvent("keypress", 0, KeyEvent.DOM_VK_F,
  Event.CONTROL_MASK | Event.SHIFT_MASK);

Similar thread: viewtopic.php?f=6&t=2130
morat
 
Posts: 959
Joined: Wed Dec 28, 2011 2:38 pm

Re: Simulate ctrl+shift+v and f

Postby steve.marks59 » Sat Aug 26, 2017 10:38 am

@morat: Where could I find a list of keyboard keys with their KeyEvent.DOM_VK_name or Event.name_MASK.
I think I understand one would use the uppercase character itself in the code such as for a
Code: Select all
g
use
Code: Select all
KeyEvent.DOM_VK_G

and for
Code: Select all
ALT
use
Code: Select all
Event.ALT_MASK


But I don't know what to use for keys like ` ^ PGDN.

Is the
Code: Select all
KeyEvent.DOM_VK_
used only to simulate pressing a character's key and codes like
Code: Select all
Event.ALT_MASK
used to simulate pressing a key which performs a function?

I would really like the code for the
Code: Select all
`
character. I am not sure what the correct name is.
I find various names such as BACKTICK and GRAVE ACCENT and BACK QUOTE.

Holding the SHIFT key and pressing the same key types a
Code: Select all
~
which is a tilde.
steve.marks59
 
Posts: 455
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware

Re: Simulate ctrl+shift+v and f

Postby morat » Sat Aug 26, 2017 4:51 pm

@steve.marks59

Try inspecting the objects with the DOM Inspector extension.

Code: Select all
/*Code*/
inspectObject(KeyEvent);

Code: Select all
/*Code*/
inspectObject(Event);

Or inspect the objects in the browser console.

* set devtools.chrome.enabled pref to true
* open browser console
* type "KeyEvent" in text field
* press return
* click function to show object properties

Or search Google...

Constants for keyCode value
http://developer.mozilla.org/en-US/docs ... Code_value

Constants for nsIDOMEvent
https://developer.mozilla.org/en-US/doc ... #Constants
morat
 
Posts: 959
Joined: Wed Dec 28, 2011 2:38 pm

Re: Simulate ctrl+shift+v and f

Postby steve.marks59 » Tue Aug 29, 2017 6:10 am

THANKS morat for this useful info. I will use DOM Inspector.
steve.marks59
 
Posts: 455
Joined: Fri Dec 23, 2011 11:23 pm
Location: Claymont, Delaware


Return to General Discussion

cron