-2

I need a checkbox function for a userscript in JavaScript that I'm editing. The checkbox should trigger the hotkey combination: ctrl++

I'm raw fresh at JavaScript so if you could keep it dummy simple I would apreaciate it dearly.

I tried searching for checkbox features that trigger hotkeys before with no luck. Hope someone can help.

In advance, thanks

/Alex

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • I'm assuming you're trying to make the browser zoom in, which is not possible via code. – Rory McCrossan Mar 31 '14 at 10:40
  • No, actually this is a userscript for a game called Kdice. In short it's a risk based game with stacks of dice instead of troops. When I press that key combination while on that site, it triggers to hide the dice, so I can view the map better. So basicly I want a checkbox to trigger that hotkey combo with a userscript. – user3480702 Mar 31 '14 at 10:44

1 Answers1

1

Try This Code

HTML

<input type="checkbox" id="triggers" /> trigger me

JS

    $('body').keydown(function(e){
    if(e.ctrlKey){
    switch(e.which){
        case 17: e.preventDefault();
            break;
        case 107:
            alert("ctrl++");
              e.preventDefault();
            break;
        default:
            break;
    }
    }
});

$('input:checkbox').click(function(e){
    if($(this).is(':checked')){
      var e=$.Event('keydown');
         e.which=107;
        e.ctrlKey=true;
       $('body').trigger(e);

    }
});

DEMO HERE

Kiranramchandran
  • 2,094
  • 16
  • 30