code examples for custom keys

Showing 1-7 of 7 messages
code examples for custom keys Rahul Abrol 8/28/12 1:43 AM
1. say you want a key that scrolls half a page (like in vi).  the code would look something like:

window.scrollBy(0, window.innerHeight / 2)

this won't work in safari reader though, so use the internal "scroll" function instead:

scroll(this, 0, window.innerHeight / 2)

(you can examine KS's internal functions by looking at end.js in the web inspector).

2. say you want a key to do something different on one particular site:

if (location.host == "planet.webkit.org")
    location.assign("http://www.webkit.org/blog");
else
    focuser();

this creates a Focus Field keystroke on all sites except planet webkit, where hitting the key would instead take you to the safari blog.
Re: code examples for custom keys Rahul Abrol 8/30/12 1:37 AM
3. here's a more complex example to enable Page Down on gmail.  several steps are required:

a. remove mail.google.com from the list of Disabled Sites.
b. add mail.google.com to the list of Force Active Automatically (since it uses frames).
c. change the list of Disabled Elements to an asterisk * (otherwise it conflicts with composing mail).

finally, create a new key with (roughly) this code:

if (location.host == "mail.google.com")
    scroll(document.getElementById(":rp"), 0, window.innerHeight / 2);
else
    scroll(this, 0, window.innerHeight-keys.bool.pagepx)

and remember to clear your old Page Down keystroke.
Re: code examples for custom keys Alexander Belyaev 3/16/16 9:25 AM
Can we create our own key for, say, activating a specific tab? I tried to use this code for activating the last tab:

safari.application.activeBrowserWindow.tabs[safari.application.activeBrowserWindow.tabs.length-1].activate();

But it shows undefined error in the console.
Re: code examples for custom keys Rahul Abrol 3/16/16 9:40 AM
You can only use plain JavaScript to create your own keys.  The
safari.application.* code is part of Apple's API so that won't work.

There already is a key to select the last tab (bound to the number 9
key) if you missed it.  You can change it to Ctrl-9 in Advanced
Preferences, but those are the only options.

Best,
Rahul
Re: code examples for custom keys Alexander Belyaev 3/16/16 9:49 AM

I'd rather have it binded to command key, because in Safari 9 cmd-numbers switch tabs by default, and cmd-9 switches to the last tab in Firefox and Chrome. Any chance of having cmd as an option for tab switching modifier, along with Ctrl?

--
You received this message because you are subscribed to a topic in the Google Groups "KeyStrokeGroup" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/keystrokegroup/rxo36DF3KGc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to keystrokegrou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Re: code examples for custom keys Rahul Abrol 3/16/16 10:50 AM
Everybody wants it bound to Cmd instead, but that never worked in Safari
< 9.  I haven't tested it recently, but if it works then I could add it
in a future release.

I need to rewrite the whole extension at some point and release it as
KeyStroke 3.  I don't like how Apple now charges $99 / year just to
write extensions so I haven't bothered yet.

Rahul
Re: code examples for custom keys Alexander Belyaev 3/16/16 11:10 AM
You've got a point) But thanks anyway.



Rahul

--
You received this message because you are subscribed to a topic in the Google Groups "KeyStrokeGroup" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/keystrokegroup/rxo36DF3KGc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to keystrokegrou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.