This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

ابحث في الدعم

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Simulate Alt-Key Down

  • 7 ردود
  • 1 has this problem
  • 1 view
  • آخر ردّ كتبه Yaron

more options

I'd like to create a toolbar button simulating Alt down (in order to select links' text; - I'm aware of the various extensions addressing the issue).

Also, I'd like to have a toolbar button simulating Alt+Shift pressed (switching between the system languages).

I haven't been able to make it work with "document.createEvent("KeyboardEvent");".

I'd be grateful for your help.

I'd like to create a toolbar button simulating Alt down (in order to select links' text; - I'm aware of the various extensions addressing the issue). Also, I'd like to have a toolbar button simulating Alt+Shift pressed (switching between the system languages). I haven't been able to make it work with "document.createEvent("KeyboardEvent");". I'd be grateful for your help.

Modified by Yaron

All Replies (7)

more options

Can you explain better what it is you want to do please?

more options

Hello FredMcD,

1) A button toggling the state of the Alt key: down - links are rendered as regular text; up- normal rendering of links.

2) A button enabling to switch between the the available system languages (English, French etc.).

Thank you.

Modified by Yaron

more options

1) Link Toggler {web link} Want to copy a part of text but this text is a link? We'll help you! This addon toggles links on a web page. Simple run "Ctrl+Shift+L" (or Alt or Cmd instead of Ctrl, depends on your system settings) to toggle links on a page.


2) http://www.bing.com/search?q=toggle+language+computer


I hope these help you.

more options

Firefox has limits on what synthetically generated keyboard events it will honor for web pages (including bookmarklets), so what you're proposing to do might not be possible in "unprivileged" code.

Are you using the CustomButtons extension, or creating a new extension, to try to work around those limits?

more options

Thank you FredMcD and jscher2000. I appreciate your help.

Link Toggler is a good extension. Select like a Boss is also very good.

Still, I'd like to try simulating Alt down and up.

---

I've created an extension for my personal use, and I'd like to include the discussed button in it.

Best regards.

more options

I'm not sure how you would like to activate this button. If you click this button then you only have this event in this button and not for a link on a web page. You would have to take over the action code in browser.js to make this work or at least invoke the command with event.altKey set.

Switching the keyboard layout is a OS action and I don't think that you can accomplish this in any way in Firefox. Any way it is usually not a good idea to have a shortcut that cycles through various layouts because you never know if you aren't activating such a switch if you invoke a shortcut in Firefox via a command that uses Alt+Shift. A direct shortcut to select each layout is better to avoid such an accidental switch.

more options

Thank you cor-el. I appreciate your help too. :)

1) That's a good point, and hence my question. I haven't looked at the relevant code in browser.js. I should definitely do that.

2) I've been using the following code to switch between the system languages:

Components.utils.import("resource://gre/modules/ctypes.jsm"); let lib = ctypes.open("user32.dll"); let switchLanguage = lib.declare("ActivateKeyboardLayout", ctypes.winapi_abi, ctypes.voidptr_t, ctypes.voidptr_t, ctypes.uint32_t); switchLanguage(ctypes.voidptr_t(1), 0x00000100); lib.close();

It has a minor glitch: When returning from Sleep Mode (Win 7) the input language is changed but the language displayed in the task bar is frequently wrong. It happens with other apps as well (e.g. Word).

"ctypes" could be used for simulating Alt down and up as well. I don't know how to do that. I'd appreciate any further help.

Best regards.