I would like to create and fire a KeyPress Event through a userscript in Greasemonkey but I observed that the createEvent's isTrusted
is set to false
all the time.
isTrusted
is read-only property but I read that it can be set to True by extensions like Greasemonkey but it's not working for me.
Is there a way to set isTrusted
to true
?.
I would like to create and fire a KeyPress Event through a userscript in Greasemonkey but I observed that the createEvent's isTrusted
is set to false
all the time.
isTrusted
is read-only property but I read that it can be set to True by extensions like Greasemonkey but it's not working for me.
Is there a way to set isTrusted
to true
?.
- Not a solution, but may be my old workaround with Python and WinApi is related: stackoverflow./a/78567959/10141885 – halt9k Commented Jun 2, 2024 at 23:53
2 Answers
Reset to default 4No. You cannot currently do this with Greasemonkey. For the most part, Greasemonkey just runs javascript, and javascript can't set isTrusted
. It would defy the spec and defeat the whole purpose of trusted events.
That said, theoretically, a Firefox add-on should be able to spoof isTrusted
, but Greasemonkey has not extended that capability to its users.
There is a feature request to add isTrusted
capability to Greasemonkey. You can go there and add your voice to the discussion, or you can fork the Greasemonkey code and add the capability yourself.
There is a related question for Google Chrome, but spoofing isTrusted
may not be possible in that browser, even for extensions.
Theoretically, you could create a trusted event with a WebSocket that JavaScript uses to municate to a Python script running in the background which would press the key, but that's a lot of code.
Python code:
import asyncio
import websockets
import pyautogui
async def watchlist(websocket, path):
while (1==1):
key = await websocket.recv()
pyautogui.press(key)
start_server = websockets.serve(watchlist, "localhost", 8765)
asyncio.get_event_loop().run_until_plete(start_server)
asyncio.get_event_loop().run_forever()
JS code to press key:
ws = new WebSocket("ws://localhost:8765")
function sendkey(key){
ws.send(key)
}
sendkey('a')
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744138684a4560180.html
评论列表(0条)