<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How send CTRL+I from Tampermonkey script.]]></title><description><![CDATA[<p dir="auto">How send CTRL+I from Tampermonkey script to browser.</p>
<p dir="auto">I try to send in Opera CTRL+I key combination to invoke a shortcut saved in the browser settings,</p>
<p dir="auto">I have tried many methods, but no code wants to work.</p>
<p dir="auto">If I click my icon I see Alert with text, but the key combination does not work.</p>
<pre><code>icon.addEventListener('click', () =&gt; {

var ciEvent = new KeyboardEvent("keydown", {

key: "i",

keyCode: 73,

which: 73,

code: "KeyI",

location: 0,

altKey: false,

ctrlKey: true,

metaKey: false,

shiftKey: false,

repeat: false

});

// get the active element and dispatch the events to it

var activeElement = document.activeElement;

if (activeElement) {

activeElement.dispatchEvent(ciEvent);

alert('WORK OK');

}

});
</code></pre>
<pre><code>
************************
code execution:

const event = new InputEvent('input', {

inputType: 'insertText',

data: 'i',

isComposing: false

});

document.activeElement.dispatchEvent(event);

console.log('InputEvent dispatched:', event);

alert('WORK OK');

return:
_app-b1721212d74c071b.js:27 InputEvent dispatched: InputEvent{isTrusted: false, data: 'i', isComposing: false, inputType: 'insertText', dataTransfer: null,…}

and sending keys doesn't work.

After pressing the keys manually

return:

Keydown event caught: KeyboardEvent{isTrusted: true, key: 'Control', code: 'ControlLeft', location: 1, ctrlKey: true,…}

_app-b1721212d74c071b.js:27 Keydown event caught: KeyboardEvent{isTrusted: true, key: 'i', code: 'KeyI', location: 0, ctrlKey: true,…}

_app-b1721212d74c071b.js:27 Ctrl+I detected!
</code></pre>
<p dir="auto">It seems that the browser blocks the sending of keys with a script.</p>
]]></description><link>https://forums.opera.com/topic/73187/how-send-ctrl-i-from-tampermonkey-script</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 16:39:18 GMT</lastBuildDate><atom:link href="https://forums.opera.com/topic/73187.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 02 Aug 2024 10:14:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How send CTRL+I from Tampermonkey script. on Fri, 02 Aug 2024 14:01:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/122">@burnout426</a><br />
Strangely, a similar script that sends the ALT and ENTER keys to a specific page (not the browser in general) works without a problem. I don't know where the error is.</p>
]]></description><link>https://forums.opera.com/post/357010</link><guid isPermaLink="true">https://forums.opera.com/post/357010</guid><dc:creator><![CDATA[MajesticF]]></dc:creator><pubDate>Fri, 02 Aug 2024 14:01:20 GMT</pubDate></item><item><title><![CDATA[Reply to How send CTRL+I from Tampermonkey script. on Fri, 02 Aug 2024 13:25:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forums.opera.com/uid/824791">@MajesticF</a> said in <a href="/post/356993">How send CTRL+I from Tampermonkey script.</a>:</p>
<blockquote>
<p dir="auto">It seems that the browser blocks the sending of keys with a script.</p>
</blockquote>
<p dir="auto">Yeah, I think synthetic events like that are blocked. I don't even think that will work with direct JS with a script in a web page, so it's probably not a Tampermonkey-specific issue.</p>
]]></description><link>https://forums.opera.com/post/357006</link><guid isPermaLink="true">https://forums.opera.com/post/357006</guid><dc:creator><![CDATA[burnout426]]></dc:creator><pubDate>Fri, 02 Aug 2024 13:25:06 GMT</pubDate></item></channel></rss>