my_custom_keys plugin stub

Post plugins and custom CSS snippets here
cjbnc
Bear Rating Trainee
Bear Rating Trainee
Posts: 6
Joined: 16 Mar 2013, 17:42

my_custom_keys plugin stub

Postby cjbnc » 19 Mar 2013, 00:48

This is a stub. Rather than try to have everyone's favorite hotkey settings added to the code as an infinite list of new plugins, it seemed like a good idea to provide one stub plugin that anyone could easily customize to fit their own site. I simply modified the swap_jk plugin and added a lot of comments and a couple examples. Note that it already includes the new *=Shift prefix.

plugins/my_custom_keys/init.php-dist:

Code: Select all

<?php
// Plugin: my_custom_keys
//    provides a hotkey plugin that can be customized to your site
//
// By default, this plugin does nothing.
// You must enable it, and add your own hotkey maps.
// (Why? So future updates will not overwrite your customized init.php.
//  They will only update the init.php-dist file.)
//
// To enable the script:
//     cd plugins/my_custom_keys (this directory)
//     cp init.php-dist init.php
//
// Next, edit your copy init.php and customize the hook_hotkey_map function.
//
// Finally, reload your tt-rss web session. Enable the plugin in
//   Actions -> Preferences -> Plugins -> User Plugins.
//

// What if you want per-user hotkeys?
//     There's currently no way for a user to customize their own keys.
//     You can provide multiple hotkey plugins, if you like.
//     To do so:
//         make a new plugins/user1_keys directory
//         copy this init.php file to that directory
//         change this class name to a unique name, e.g. "User1_Custom_Keys"
class My_Custom_Keys extends Plugin {

   private $link;
   private $host;

// You can change the description of this plugin here
   function about() {
      return array(1.0,
         "Enable site-specific hotkey maps",
         "cjbnc");
   }

   function init($host) {
      $this->link = $host->get_link();
      $this->host = $host;

      $host->add_hook($host::HOOK_HOTKEY_MAP, $this);
   }

// This is where the hotkey maps are defined. You can uncomment
// the example codes below, or add your own.
//
// Each map looks like this:
//      $hotkeys[KEYS] = "KEY_FUNCTION";
//
// KEYS can be:
//      "n"             = a single key character
//      "*n"            = Shift + key character  (Shift-n)
//      "^n"            = Ctrl + key character   (Ctrl-n)
//      "f q"           = a sequence of two keys
//      "(37)|left"     = a javascript key code and label
//      "^(38)|Ctrl-Up" = can use * Shift or ^ Ctrl with key codes
//  (search the web for "javascript key codes" for more examples)
//
// KEY_FUNCTION can be any of the functions defined by
// get_hotkeys_info() located in the file include/functions.php
//
// The default hotkey bindings are defined by
// get_hotkeys_map()  also located in the file include/functions.php

   function hook_hotkey_map($hotkeys) {

        // Example: Swap the functions of the j/k keys for vim users

      // $hotkeys["j"] = "next_feed";
      // $hotkeys["k"] = "prev_feed";

        // Example: Arrow key navigation

        // $hotkeys["(37)|left"]  = "prev_article";
        // $hotkeys["(39)|right"] = "next_article";
        // $hotkeys["(38)|up"]    = "article_scroll_up";
        // $hotkeys["(40)|down"]  = "article_scroll_down";

      return $hotkeys;

   }
}

// vim:ft=php
?>


This is on github so I can make it a Pull Request if you like, fox.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: my_custom_keys plugin stub

Postby fox » 19 Mar 2013, 01:08

It's probably better off stickied here and in the KB maybe; otherwise people would try to enable it and whine that nothing works or whatever.

cjbnc
Bear Rating Trainee
Bear Rating Trainee
Posts: 6
Joined: 16 Mar 2013, 17:42

Re: my_custom_keys plugin stub

Postby cjbnc » 19 Mar 2013, 19:08

Another example, to provide similar arrow-key navigation, per this post: viewtopic.php?t=1399&p=6163

Code: Select all

      $hotkeys['(13)|enter']   = 'open_in_new_window';
      $hotkeys['(37)|left']    = 'prev_article_noscroll';
      $hotkeys['(38)|up']      = 'article_scroll_up';
      $hotkeys['(39)|right']   = 'next_article_noscroll';
      $hotkeys['(40)|down']    = 'article_scroll_down';
      $hotkeys['*(38)|s-up']   = 'prev_feed';
      $hotkeys['*(40)|s-down'] = 'next_feed';

cjbnc
Bear Rating Trainee
Bear Rating Trainee
Posts: 6
Joined: 16 Mar 2013, 17:42

Re: my_custom_keys plugin stub

Postby cjbnc » 18 Apr 2013, 19:40

Updated to remove the get_link() call per the recent trunk changes.

Code: Select all

<?php
// Plugin: my_custom_keys
//    provides a hotkey plugin that can be customized to your site
//
// By default, this plugin does nothing.
// You must enable it, and add your own hotkey maps.
// (Why? So future updates will not overwrite your customized init.php.
//  They will only update the init.php-dist file.)
//
// To enable the script:
//     cd plugins/my_custom_keys (this directory)
//     cp init.php-dist init.php
//
// Next, edit your copy init.php and customize the hook_hotkey_map function.
//
// Finally, reload your tt-rss web session. Enable the plugin in
//   Actions -> Preferences -> Plugins -> User Plugins.
//

// What if you want per-user hotkeys?
//     There's currently no way for a user to customize their own keys.
//     You can provide multiple hotkey plugins, if you like.
//     To do so:
//         make a new plugins/user1_keys directory
//         copy this init.php file to that directory
//         change this class name to a unique name, e.g. "User1_Custom_Keys"
class My_Custom_Keys extends Plugin {

   private $host;

// You can change the description of this plugin here
   function about() {
      return array(1.0,
         "Enable site-specific hotkey maps",
         "cjbnc");
   }

   function init($host) {
      $this->host = $host;

      $host->add_hook($host::HOOK_HOTKEY_MAP, $this);
   }

// This is where the hotkey maps are defined. You can uncomment
// the example codes below, or add your own.
//
// Each map looks like this:
//      $hotkeys[KEYS] = "KEY_FUNCTION";
//
// KEYS can be:
//      "n"             = a single key character
//      "*n"            = Shift + key character  (Shift-n)
//      "^n"            = Ctrl + key character   (Ctrl-n)
//      "f q"           = a sequence of two keys
//      "(37)|left"     = a javascript key code and label
//      "^(38)|Ctrl-Up" = can use * Shift or ^ Ctrl with key codes
//  (search the web for "javascript key codes" for more examples)
//
// KEY_FUNCTION can be any of the functions defined by
// get_hotkeys_info() located in the file include/functions.php
//
// The default hotkey bindings are defined by
// get_hotkeys_map()  also located in the file include/functions.php

   function hook_hotkey_map($hotkeys) {

        // Example: Swap the functions of the j/k keys for vim users

      // $hotkeys["j"] = "next_feed";
      // $hotkeys["k"] = "prev_feed";

        // Example: Arrow key navigation

        // $hotkeys["(37)|left"]  = "prev_article";
        // $hotkeys["(39)|right"] = "next_article";
        // $hotkeys["(38)|up"]    = "article_scroll_up";
        // $hotkeys["(40)|down"]  = "article_scroll_down";

      return $hotkeys;

   }
}

// vim:ft=php
?>

jmozmoz
Bear Rating Trainee
Bear Rating Trainee
Posts: 26
Joined: 14 Apr 2013, 18:07

Re: my_custom_keys plugin stub

Postby jmozmoz » 20 Apr 2013, 00:48

You have to add

Code: Select all

        function api_version() {
                return 2;
        }


ArchCarrier
Bear Rating Trainee
Bear Rating Trainee
Posts: 16
Joined: 04 Apr 2013, 20:35

Re: my_custom_keys plugin stub

Postby ArchCarrier » 25 Apr 2013, 12:25

What's the safest way to disable all existing hotkeys? I don't want to touch core files, so I tried adding

Code: Select all

unset($GLOBALS['hotkeys']);

to the init function, but that doesn't work. Any ideas?

phz
Bear Rating Disaster
Bear Rating Disaster
Posts: 77
Joined: 18 Mar 2013, 18:32

Re: my_custom_keys plugin stub

Postby phz » 25 Apr 2013, 13:07

ArchCarrier wrote:What's the safest way to disable all existing hotkeys? I don't want to touch core files, so I tried adding

Code: Select all

unset($GLOBALS['hotkeys']);

to the init function, but that doesn't work. Any ideas?

Return an empty array in the `hook_hotkey_map()` function.

If you meant that you want to disable all built-in hotkeys and just use the ones you define yourself, just return an array with your own definitions in the above mentioned function (i.e. create a new array instead of reusing the function argument and return that).

ArchCarrier
Bear Rating Trainee
Bear Rating Trainee
Posts: 16
Joined: 04 Apr 2013, 20:35

Re: my_custom_keys plugin stub

Postby ArchCarrier » 25 Apr 2013, 16:28

Thanks, that worked!

GravityWell
Bear Rating Trainee
Bear Rating Trainee
Posts: 10
Joined: 13 Apr 2013, 01:48

Re: my_custom_keys plugin stub

Postby GravityWell » 26 Apr 2013, 22:03

Thanks for this plugin. I used the following:

Code: Select all

$hotkeys['(39)|right']   = 'next_article_noscroll';
$hotkeys['(37)|left']    = 'prev_article_noscroll';

Nice to have that option for feeds with large articles.

GravityWell
Bear Rating Trainee
Bear Rating Trainee
Posts: 10
Joined: 13 Apr 2013, 01:48

Re: my_custom_keys plugin stub

Postby GravityWell » 24 May 2013, 17:38

Any idea how to get page down functionality mapped to a key? In Chrome, if the focus is in the article list, page down (or space bar) advances to the next visible page of articles. The issue is getting the focus to the article list is a bit awkward, especially on a tablet, and I'd rather set pgup/pgdn to perform this function globally, even if the focus is in the feed list.

ArchCarrier
Bear Rating Trainee
Bear Rating Trainee
Posts: 16
Joined: 04 Apr 2013, 20:35

Re: my_custom_keys plugin stub

Postby ArchCarrier » 24 May 2013, 21:10

Yes, I've noticed this as well. It appears to be a bug.

User avatar
recognitium
Bear Rating Trainee
Bear Rating Trainee
Posts: 14
Joined: 02 Jul 2013, 01:35

Re: my_custom_keys plugin stub

Postby recognitium » 30 Jul 2013, 13:59

Hi everybody,

--edit --
first part of question solved. Sorry for not being good at forum searches.
--end edit--

As a side issue, for those who are in fact developers / have experience with tt-rss code and plugins : do you think it would be achievable/easy to try to make articles open/select in the position they are? As for now, whenever an article is select for opening, it becomes the first on the list. (i wonder if maybe this could be so easy as to create a custom theme mod)

Thanks for the patience and for all the great work around tt-rss

timmmmyboy
Bear Rating Trainee
Bear Rating Trainee
Posts: 3
Joined: 16 Feb 2014, 21:18

Re: my_custom_keys plugin stub

Postby timmmmyboy » 16 Feb 2014, 21:22

Is there any way to use this plugin to hook into the share buttons and article note feature at the bottom of each article? Anyone doing anything like that? I use keyboard shortcuts for most of what I do in TT-RSS and it would be convenient to not have to scroll and find buttons to click on.

User avatar
fox
^ me reading your posts ^
Posts: 6318
Joined: 27 Aug 2005, 22:53
Location: Saint-Petersburg, Russia
Contact:

Re: my_custom_keys plugin stub

Postby fox » 16 Feb 2014, 23:16

You can put arbitrary javascript in a hotkey handler so yes you can do that.

timmmmyboy
Bear Rating Trainee
Bear Rating Trainee
Posts: 3
Joined: 16 Feb 2014, 21:18

Re: my_custom_keys plugin stub

Postby timmmmyboy » 17 Feb 2014, 03:12

Thanks! I'll give it a shot.


Return to “Themes and plugins”

Who is online

Users browsing this forum: No registered users and 1 guest