0

I am trying to detect key combination (ctrl+tab), but my code doesn't seem to work. In fact keydown only fires when i press ctrl and as i press tab browser just switches the tab without firing any event.

$(document).keydown(function(e) {
    if (e.ctrlKey && e.which === 9) {
        alert("CTRL_TAB pressed");
    } });

Can any one help me out here? what is the issue with this code. I am using chrome Version "53.0.2785.116".

Use Case: I need this to resize my video element. since it is pressed when user in full screen mode. l can see you tube does the same. when user in full screen mode and ctrl+tab is pressed it will resize the video to small video. I want to achieve similar behaviour.

piyush
  • 868
  • 13
  • 29
  • I would look at e.keyCode. Check this out: http://keycode.info/ You can press a key and see it's keyCode. Seems like for me the Ctrl key has a keyCode of 17. So I would check if (e.keyCode === 17) – Theodoros Klikas Sep 21 '16 at 11:07
  • 2
    some key combinations are not available to a web page, for good reason, they are operating system or application specific functions that should never be intercepted by a lowly web page – Jaromanda X Sep 21 '16 at 11:07
  • ctrl+tab changes the tab in chrome and is reserved! what are you trying to achieve? – Amin Jafari Sep 21 '16 at 11:09
  • Possible duplicate of [javascript capture browser shortcuts (ctrl+t/n/w)](http://stackoverflow.com/questions/7295508/javascript-capture-browser-shortcuts-ctrlt-n-w) – freedomn-m Sep 21 '16 at 11:13
  • e.keyCode comes as 17 when i put a breakpoint in browser. but when i press tab it immediately switches the tab in browser. I am editing the question to explain why i need to capture this – piyush Sep 21 '16 at 11:13
  • @freedomn-m that question doesn't answer my query. so It can not be said duplicate. moreover Answers on that question suggests similar approach to capture the key. and that doesn't seem to work for me. – piyush Sep 21 '16 at 11:14
  • Why not using minus and plus symbols? It would be intuitive to resize the video element. – Marco Sep 21 '16 at 11:32
  • While the linked question doesn't answer ctrl-tab explicitly, it *does* explain why it's not available in js: *These combinations cannot get captured by Javascript, but embed plugins can capture these.* – freedomn-m Sep 21 '16 at 12:19

2 Answers2

0

Note: In Chrome Ctrl+Tab is "reserved" for navigating brower Tabs

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
  • How does you tube able to capture these. try going full screen in you tube and press ctrl+tab. It will automatically resize the video to small video. – piyush Sep 21 '16 at 11:28
  • please check, it is not only for you tube, if you open any site video in fullscreen, and then CTRL+TAB it will become a small. make full screen is done by Google Crome and it handle when in Fullscreen mode then allow CTRL+TAB to make screen small – Haresh Vidja Sep 21 '16 at 11:56
  • This is goofy. We already have tab navigation by ctrl-page up and ctrl-page down, and that's easier to use than ctrl-tab and ctrl-shift-tab. They don't reserve regular TAB for tabbing between fields, so why this nonsense? – Sam Watkins Jan 22 '18 at 01:37
0

2023

In Chromium based browsers while in fullscreen mode (F11):

document.addEventListener('keydown', e => {
    if (e.ctrlKey) {
        if (e.key === 'Tab') {
            e.preventDefault();
            console.log('ctrl+tab'); // chromium fullscreen (think PWA)
        }
    }     
});

Chrome - Version 114.0.5735.110 (Official Build) (64-bit) Edge - Version 114.0.1823.43 (Official build) (64-bit)

A.J.Bauer
  • 2,803
  • 1
  • 26
  • 35