Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36153 > unrolled thread
| Started by | "R.Wieser" <address@not.available> |
|---|---|
| First post | 2019-03-25 08:23 +0100 |
| Last post | 2019-04-07 19:53 +0200 |
| Articles | 19 — 7 participants |
Back to article view | Back to comp.lang.javascript
How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 08:23 +0100
Re: How to check if a key is currently down ... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 02:33 -0700
Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 11:48 +0100
Re: How to check if a key is currently down ... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 02:39 -0700
Re: How to check if a key is currently down ... Julio Di Egidio <julio@diegidio.name> - 2019-03-25 04:08 -0700
Re: How to check if a key is currently down ... JJ <jj4public@vfemail.net> - 2019-03-25 19:42 +0700
Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 17:21 +0100
Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 17:09 +0100
Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 16:12 +0000
Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 17:35 +0100
Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 16:48 +0000
Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 18:29 +0100
Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 17:36 +0000
Re: How to check if a key is currently down ... Julio Di Egidio <julio@diegidio.name> - 2019-03-26 18:23 -0700
Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-03-25 18:46 +0100
Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 19:23 +0100
Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-03-27 19:26 +0100
Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-04-05 09:23 +0200
Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-04-07 19:53 +0200
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-03-25 08:23 +0100 |
| Subject | How to check if a key is currently down ... |
| Message-ID | <q79vlh$1li$1@gioia.aioe.org> |
... without having to capture it thru an event first. The reason I'm stating it like that is because I have the need to see if a certain key (preferrably the shift, alt, ctrl or similar) is down /when a webpage is being loaded/. In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method. Does such a beast exist ? Regards, Rudy Wieser P.s. For the off chance that it might make a difference: The script is actually a GreaseMonkey one. I want to alter its behaviour (scrubbing less or more) depending on certain keys being pressed while loading a new page.
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-03-25 02:33 -0700 |
| Message-ID | <a6da5c6a-3844-41e5-b8c5-cf48f2e92a8d@googlegroups.com> |
| In reply to | #36153 |
Den måndag 25 mars 2019 kl. 08:23:36 UTC+1 skrev R.Wieser:
> ... without having to capture it thru an event first.
>
> The reason I'm stating it like that is because I have the need to see if a
> certain key (preferrably the shift, alt, ctrl or similar) is down /when a
> webpage is being loaded/.
>
> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method.
> Does such a beast exist ?
>
> Regards,
> Rudy Wieser
>
> P.s.
> For the off chance that it might make a difference: The script is actually a
> GreaseMonkey one. I want to alter its behaviour (scrubbing less or more)
> depending on certain keys being pressed while loading a new page.
https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
There are far more suitable persons then me to adress this, i know practically no syntax, but this is how i would solve it you add an eventlistener in
<script> </script>.
document.addEventListener('keydown', function(event){
charCode=event.keyCode;
//Keycode 17 is CTRL
if (charCode==17) runMyFunction();
} );
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-03-25 11:48 +0100 |
| Message-ID | <q7abmj$1o9h$1@gioia.aioe.org> |
| In reply to | #36154 |
Jonas, Thanks for your reply, but ... > this is how i would solve it you add an eventlistener in .... that is exactly how it /wouldn't/ work. Those listeners listen for new(!) changes. And as the key is already down when the listener is installed ... > But of course you can not check for "down" only "pressed" > as far i know. Thanks. And yes, that is what I'm trying to find out. :-) I need that "down" status (the "up-to-down change is easy enough to detect and capture. My googleling (before I posted here) returned multiple examples in that regard). Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-03-25 02:39 -0700 |
| Message-ID | <c7497d36-7759-46ee-bfb4-b1cf88a9e1ad@googlegroups.com> |
| In reply to | #36153 |
Den måndag 25 mars 2019 kl. 08:23:36 UTC+1 skrev R.Wieser: > ... without having to capture it thru an event first. > > The reason I'm stating it like that is because I have the need to see if a > certain key (preferrably the shift, alt, ctrl or similar) is down /when a > webpage is being loaded/. > > In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method. > Does such a beast exist ? > > Regards, > Rudy Wieser > > P.s. > For the off chance that it might make a difference: The script is actually a > GreaseMonkey one. I want to alter its behaviour (scrubbing less or more) > depending on certain keys being pressed while loading a new page. But of course you can not check for "down" only "pressed" as far i know.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-03-25 04:08 -0700 |
| Message-ID | <6e9f4318-9d7f-4c86-8fdb-f2452eabcdb6@googlegroups.com> |
| In reply to | #36153 |
On Monday, 25 March 2019 08:23:36 UTC+1, R.Wieser wrote:
> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method.
> Does such a beast exist ?
If the user keeps a key down, key events fire repeatedly. (There are some
quirks to this: e.g. if you press Shift, then A, then release A, Shift will
not continue firing, but this is how things work beyond the level you can
control from JS in the browser from an unprivileged script...)
So, just attach a handler for keydown to the window as early as possible in
the document and, if the user is keeping a key down, the event is going to
fire straight away. (You can detach the handler from itself if it fired,
otherwise from window load, or after a timeout, anyway possibly started from
window load.)
This is a very basic example that seems to do the job: to test, keep any key
down, even a modifier, while loading or reloading the page (click the reload
button with the mouse while keeping e.g. the Shift key down):
----------------------------------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<script>
window.addEventListener("keydown", function (event) {
var disp = document.getElementById("disp");
var div = document.createElement("div");
div.innerHTML = event.key + "<br>\n";
disp.appendChild(div);
}, false);
</script>
</head>
<body>
<div id="disp"></div>
</body>
</html>
----------------------------------
HTH,
Julio
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-03-25 19:42 +0700 |
| Message-ID | <14dc5q8q828ot$.egjb1au5kypn.dlg@40tude.net> |
| In reply to | #36153 |
On Mon, 25 Mar 2019 08:23:24 +0100, R.Wieser wrote: > .... without having to capture it thru an event first. > > The reason I'm stating it like that is because I have the need to see if a > certain key (preferrably the shift, alt, ctrl or similar) is down /when a > webpage is being loaded/. > > In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method. > Does such a beast exist ? No. Keyboard inputs on client side scripts are only event based. There's no method that can retrieve a keyboard key status on demand. > P.s. > For the off chance that it might make a difference: The script is actually a > GreaseMonkey one. I want to alter its behaviour (scrubbing less or more) > depending on certain keys being pressed while loading a new page. There's a way but it's unreliable. It'll heavily depend on the keyboard repeat feature, and assuming that no other key is pressed (which would stop the input event from repeating).
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-03-25 17:21 +0100 |
| Message-ID | <q7av6o$l1r$1@gioia.aioe.org> |
| In reply to | #36162 |
JJ, >> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown >> method. Does such a beast exist ? > > No. Keyboard inputs on client side scripts are only event based. I was already afraid of it (my googeling didn't show anything). :-( > There's a way but it's unreliable. It'll heavily depend on the > keyboard repeat feature Yep, I think that would it work ... ish. It would mean that after the listner is installed a delay is needed to allow the (repeated) key down event to show up and be caught (slowing down every related page opening). Thanks for the hint. Its something to try. :-) Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2019-03-26 17:09 +0100 |
| Message-ID | <4401b01e-8b83-3bfe-73be-ca0757c98d80@PointedEars.de> |
| In reply to | #36162 |
JJ wrote: > On Mon, 25 Mar 2019 08:23:24 +0100, R.Wieser wrote: >> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method. >> Does such a beast exist ? > > No. Keyboard inputs on client side scripts are only event based. There's no > method that can retrieve a keyboard key status on demand. Wrong. *Event*s can be *create*d and *dispatch*ed programmatically. <https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent> pp. -- PointedEars Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Date | 2019-03-26 16:12 +0000 |
| Message-ID | <slrnq9kjqu.6qm.jon+usenet@sable.unequivocal.eu> |
| In reply to | #36173 |
On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: > JJ wrote: >> On Mon, 25 Mar 2019 08:23:24 +0100, R.Wieser wrote: >>> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method. >>> Does such a beast exist ? >> >> No. Keyboard inputs on client side scripts are only event based. There's no >> method that can retrieve a keyboard key status on demand. > > Wrong. *Event*s can be *create*d and *dispatch*ed programmatically. > ><https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent> pp. As far as I can see that means that you can write code to cause other code to *think* a key has been pressed when it hasn't; it doesn't allow one to write code to detect whether a key actually is currently pressed if the code did not have the opportunity to receive a keydown event (i.e. because the key was pressed down before the code loaded).
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2019-03-26 17:35 +0100 |
| Message-ID | <011e45b6-1925-8b27-94c4-7aafc5094b5f@PointedEars.de> |
| In reply to | #36174 |
Jon Ribbens wrote:
> On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> JJ wrote:
>>> On Mon, 25 Mar 2019 08:23:24 +0100, R.Wieser wrote:
>>>> In short, I'm looking for a(n equivalent of) IsKeyCurrentlyDown method.
>>>> Does such a beast exist ?
>>>
>>> No. Keyboard inputs on client side scripts are only event based. There's no
>>> method that can retrieve a keyboard key status on demand.
>>
>> Wrong. *Event*s can be *create*d and *dispatch*ed programmatically.
>>
>> <https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent> pp.
>
> As far as I can see that means that you can write code to cause other
> code to *think* a key has been pressed when it hasn't; it doesn't
> allow one to write code to detect whether a key actually is currently
> pressed if the code did not have the opportunity to receive a keydown
> event (i.e. because the key was pressed down before the code loaded).
OK, that is correct. (I had not read the quote carefully enough.)
However, the previous answer is still wrong because there is nothing that
says that keyboard events are not fired or cannot be handled while “a
webpage is being loaded”. So that is worth a try.
Proof of concept:
var w = window.open('', 'foo', 'width=400,height=400');
w.document.open();
w.document.write('<!doctype html><html><head><title>Shift key
status</title></head><body onkeydown="this.textContent = event.shiftKey;"
onkeyup="this.textContent = event.shiftKey;"></body>');
w.document.close();
Press down the Shift key immediately after you execute that code (in the
Console). You should see “true” in the popup when it has loaded.
[window.open() cannot be triggered in a window.setTimeout() callback if such
popups that are not directly initiated by the user are blocked.]
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Date | 2019-03-26 16:48 +0000 |
| Message-ID | <slrnq9klu7.6qm.jon+usenet@sable.unequivocal.eu> |
| In reply to | #36175 |
On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> However, the previous answer is still wrong because there is nothing that
> says that keyboard events are not fired or cannot be handled while “a
> webpage is being loaded”. So that is worth a try.
>
> Proof of concept:
>
> var w = window.open('', 'foo', 'width=400,height=400');
> w.document.open();
> w.document.write('<!doctype html><html><head><title>Shift key
> status</title></head><body onkeydown="this.textContent = event.shiftKey;"
> onkeyup="this.textContent = event.shiftKey;"></body>');
> w.document.close();
>
> Press down the Shift key immediately after you execute that code (in the
> Console). You should see “true” in the popup when it has loaded.
> [window.open() cannot be triggered in a window.setTimeout() callback if such
> popups that are not directly initiated by the user are blocked.]
It doesn't work in Chrome for me; if I manage to press 'shift' quick
enough before the window opens then the window remains blank. (And in
fact if I copy'n'paste the code into the JavaScript console then
setTimeout does work to open the window after a delay and it's easy
to verify that the events don't fire until the key status changes
after the window has loaded.)
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2019-03-26 18:29 +0100 |
| Message-ID | <340f6105-cc78-29e1-11ec-252126379941@PointedEars.de> |
| In reply to | #36176 |
Jon Ribbens wrote:
> On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> However, the previous answer is still wrong because there is nothing that
>> says that keyboard events are not fired or cannot be handled while “a
>> webpage is being loaded”. So that is worth a try.
>>
>> Proof of concept:
>>
>> var w = window.open('', 'foo', 'width=400,height=400');
>> w.document.open();
>> w.document.write('<!doctype html><html><head><title>Shift key
>> status</title></head><body onkeydown="this.textContent = event.shiftKey;"
>> onkeyup="this.textContent = event.shiftKey;"></body>');
>> w.document.close();
>>
>> Press down the Shift key immediately after you execute that code (in the
>> Console). You should see “true” in the popup when it has loaded.
>> [window.open() cannot be triggered in a window.setTimeout() callback if such
>> popups that are not directly initiated by the user are blocked.]
>
> It doesn't work in Chrome for me; if I manage to press 'shift' quick
> enough before the window opens then the window remains blank.
YMMV.
> And in fact if I copy'n'paste the code into the JavaScript console then
> setTimeout does work to open the window after a delay
Yes, AISB, window.open() does not work *if* such popups are blocked.
> and it's easy to verify that the events don't fire until the key status
> changes after the window has loaded.)
YMMV. "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/57.0.2987.98 Safari/537.36", with several extensions, here.
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Jon Ribbens <jon+usenet@unequivocal.eu> |
|---|---|
| Date | 2019-03-26 17:36 +0000 |
| Message-ID | <slrnq9kooh.6qm.jon+usenet@sable.unequivocal.eu> |
| In reply to | #36177 |
On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: > Jon Ribbens wrote: >> It doesn't work in Chrome for me; if I manage to press 'shift' quick >> enough before the window opens then the window remains blank. > > YMMV. Well that's no use then. If "mileage varies" then the OP can't use this method to reliably detect the status of the shift key and their question is still unanswered. >> And in fact if I copy'n'paste the code into the JavaScript console then >> setTimeout does work to open the window after a delay > > Yes, AISB, window.open() does not work *if* such popups are blocked. I know, my point was that I was able to use setTimeout() to reliably check if Chrome was allowing the window to detect the shift status from before the window opened, without having to try and race how fast the computer would open the window vs how fast I could press the shift key.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-03-26 18:23 -0700 |
| Message-ID | <805f530b-b4a5-40bb-abf1-79d1ba14027f@googlegroups.com> |
| In reply to | #36162 |
On Monday, 25 March 2019 13:42:51 UTC+1, JJ wrote: > There's a way but it's unreliable. Reliably one can see the parade of stupid cunts spamming this group--- *Plonk* Julio
[toc] | [prev] | [next] | [standalone]
| From | Peter Büttner <not_for_mail_peb@gmx.net> |
|---|---|
| Date | 2019-03-25 18:46 +0100 |
| Message-ID | <gfsif9F4cf9U1@mid.individual.net> |
| In reply to | #36153 |
Am 25.03.2019 08:23, schrieb R.Wieser:
> ... without having to capture it thru an event first.
>
> The reason I'm stating it like that is because I have the need to see if a
> certain key (preferrably the shift, alt, ctrl or similar) is down /when a
> webpage is being loaded/.
Like the idea.
But AFAIK all/most browsers use those modifiers to open a bookmark/link
in a new window or tab, so your idea may interfere with the default
behavior.
> For the off chance that it might make a difference: The script is actually a
> GreaseMonkey one. I want to alter its behaviour (scrubbing less or more)
> depending on certain keys being pressed while loading a new page.
I do it this way:
store a bookmark with a hash:
example.org/foo/bar#MarkerToDoThings
and the GM Script looks for that.
One may store more options here.
Since nowadays some website also use the hash to store data
this may interfere with the pages original scripts. But they
are not send by the browser to the server.
Another approach maybe the useractions of GM.
Peter
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-03-25 19:23 +0100 |
| Message-ID | <q7b6b4$1mqo$1@gioia.aioe.org> |
| In reply to | #36166 |
Peter,
> Like the idea.
Thanks. :-)
> But AFAIK all/most browsers use those modifiers to open a bookmark/link in
> a new window or tab, so your idea may interfere with the default behavior.
First I have to find a way to capture a key, after that I can worry about
which one to use. Maybe even one of the printscreen, scrolllock or
pause/break ones. Or the insert, home or end ones. They seem to behave
rather neutral.
> I do it this way:
> store a bookmark with a hash:
For what I'm currently aiming at that won't work too well: I'm trying to
scrub googles result pages of the (rather random and more-often-than-not
fully unusable) "Images of {the exact searchterm}". Appending such a hash
does not seem to want to stick (just tried. :-) )
> Another approach maybe the useractions of GM.
Do you maybe have a bit more info on that ? I've just done a quick google
for it but I got back zilch. And the build-in link to the "manual" is
rather ... underwhelming. :-(
Regards,
Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Peter Büttner <not_for_mail_peb@gmx.net> |
|---|---|
| Date | 2019-03-27 19:26 +0100 |
| Message-ID | <gg1thtFa2vsU1@mid.individual.net> |
| In reply to | #36168 |
Am 25.03.2019 19:23, schrieb R.Wieser:
> Peter,
>
>> Like the idea.
>
> Thanks. :-)
>
>> But AFAIK all/most browsers use those modifiers to open a bookmark/link in
>> a new window or tab, so your idea may interfere with the default behavior.
>
> First I have to find a way to capture a key, after that I can worry about
> which one to use. Maybe even one of the printscreen, scrolllock or
> pause/break ones. Or the insert, home or end ones. They seem to behave
> rather neutral.
>
>> I do it this way:
>> store a bookmark with a hash:
>
> For what I'm currently aiming at that won't work too well: I'm trying to
> scrub googles result pages of the (rather random and more-often-than-not
> fully unusable) "Images of {the exact searchterm}". Appending such a hash
> does not seem to want to stick (just tried. :-) )
Here it stays:
<https://www.google.com/search?q=foobar&#foo>
But on the next page it is removed. Maybe store a flag with GM
and do your action on the next page if it is set, and add a button
to remove the flag, or set the flag for the search word.
Well, add the hash to all the 'next page links', that seems to stay.
Since the hash isn't send to the server only client side code can
remove it, so chances are good that tis works for a long time.
>> Another approach maybe the useractions of GM.
>
> Do you maybe have a bit more info on that ? I've just done a quick google
> for it but I got back zilch. And the build-in link to the "manual" is
> rather ... underwhelming. :-(
Before:
That may not help you since works after page load and the user needs
to activate the menuitem. That behavior can also be implemented by
a simple button anywhere on the page (hide the images always and only
show them on a click on the new created element)
The 'User Script Commands' were removed in GM 4.
To use it in older versions:
// @grant GM_registerMenuCommand
GM_registerMenuCommand("Do Foo", function(){ alert("Foo");}, "f");
That adds a menuitem to the GM Menu like in
<https://camo.githubusercontent.com/2fda602ca65f6109511d7314d4dbb6b5e4754523/687474703a2f2f7765622e617263686976652e6f72672f7765622f3230313731303035303632343335696d5f2f68747470733a2f2f77696b692e67726561736573706f742e6e65742f696d616765732f372f37612f57696e372d6666342d746f6f6c6261722d6d6f6e6b65792d6d656e752e706e67>
(Here it is grayed since no commands are registered)
https://wiki.greasespot.net/GM_registerMenuCommand
Here a discussion:
https://github.com/greasemonkey/greasemonkey/issues/2714
Since the alternative 'Context Menu' won't work there maybe
a chance that the developers reimplement those menu commands
as before.
Peter
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-04-05 09:23 +0200 |
| Message-ID | <q86vpv$1k4d$1@gioia.aioe.org> |
| In reply to | #36194 |
Peter,
Sorry for the late reply, I got a bit distracted with another project ...
> Maybe store a flag with GM and do your action on the next page if it is
> set
If I can do that (store a flag into GM space which survives page changes)
than I can probably do with the already available catching key-state change
events (or the 'User Script Commands' below).
> That behavior can also be implemented by a simple button anywhere on the
> page
I only realized that after I conceeded that getting a keystate isn't
possible and started looking for other possibilities. Heck, I've already
used a similar method elsewhere (capturing mouse clicks) ...
> The 'User Script Commands' were removed in GM 4.
I'm (still) running 3.17 (on FF 52), and yesterday saw that it indeed does
work. Bummer though, I assumed them to be some kind of page-local hotkeys,
not a Alt-T, G, C, {my key} sequence.
Thanks for the info about it though. Might come in handy elsewhere. :-)
Regards,
Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Peter Büttner <not_for_mail_peb@gmx.net> |
|---|---|
| Date | 2019-04-07 19:53 +0200 |
| Message-ID | <ggurp9Fkiq1U1@mid.individual.net> |
| In reply to | #36315 |
Am 05.04.2019 09:23, schrieb R.Wieser:
> Peter,
>
> Sorry for the late reply, I got a bit distracted with another project ...
Usenet is no chat, and I need some time to reply too.
>> Maybe store a flag with GM and do your action on the next page if it is
>> set
>
> If I can do that (store a flag into GM space which survives page changes)
GM_getValue(), GM_setValue()
like localStorage, but not accessible by the webpage.
> than I can probably do with the already available catching key-state change
> events (or the 'User Script Commands' below).
>
>> That behavior can also be implemented by a simple button anywhere on the
>> page
>
> I only realized that after I conceeded that getting a keystate isn't
> possible and started looking for other possibilities. Heck, I've already
> used a similar method elsewhere (capturing mouse clicks) ...
>
>> The 'User Script Commands' were removed in GM 4.
>
> I'm (still) running 3.17 (on FF 52), and yesterday saw that it indeed does
> work. Bummer though, I assumed them to be some kind of page-local hotkeys,
> not a Alt-T, G, C, {my key} sequence.
add an event listner to the page.
I do that on some forum sites. Just need to press a single key 'N'=Next.
Very useful.
E.g.:
map ={ 'N': 'a[rel="next"]', 'P':'a[rel="prev"]'};
and find the link and 'click' it by code after the keypress.
Google search uses special id= for next/previous links.
Here <link rel="prev"> and <link rel="next"> from older days comes
to mind, rarely used today, and AFAIK not supported by browsers any
more (in menus or with shortcuts).
Some websites (e.g. heise.de) also use single key shortcuts for
navigation.
> Thanks for the info about it though. Might come in handy elsewhere. :-)
I find the menu good for seldom used actions, as a reminder. Like menus
in 'normal' programs, real menus, not burger menus.
Peter
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web