1

How I can capture key press and click on a tr element ?

I need to implement a table that can handle a single row selection, or multiple-row selection.

Right now, I tried to bind the key ctrl:

Vue.directive('on').keyCodes.ctrl = 17;

But, if i use @keyup.ctrl sure this dont works, because I need to check what key is pressed when the user click on a row.

1 Answer 1

3

The click event includes properties that indicate whether Control, Shift, Alt, or Meta keys were pressed during the click.

new Vue({
  el: 'body',
  data: {
    controlled: false,
    shifted: false,
    meta: false,
    alted: false
  },
  methods: {
    clicked: function(event) {
      console.debug(event);
      this.controlled = event.ctrlKey;
      this.shifted = event.shiftKey;
      this.meta = event.metaKey;
      this.alted = event.altKey;
    }
  }
});
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
<button @click="clicked">Click me!</button>
<div v-if="controlled">Control was pressed</div>
<div v-if="shifted">Shift was pressed</div>
<div v-if="alted">Alt was pressed</div>
<div v-if="meta">Meta was pressed</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.