Pressing the Ctrl button to trigger a keydown event

$(document).keydown(function(event){
switch (event.keyCode){
case 13:
    btnplay();
    $("#short").text("enter");
    break;
case 39:
    btnext();
    $("#short").text("left");
    break;
};
});

While the current setup is functional, a modification is now required where instead of case 13 and case 39, we need to incorporate case Ctrl+13 and case Ctrl+39.

Is there a way to achieve this?

Answer №1

If you want to detect if the ctrl key is pressed, you can use event.ctrlKey. Here's an example:

$(document).on('keydown', 
 function(event){
  if (event.ctrlKey) { 
 //         ^ this line checks for ctrl key press
    switch (event.keyCode) {
      case 13:
        $("#short").text("CTRL + enter");
        break;
      case 37:
        $("#short").text("CTRL + left");
        break;
     }
    }
  }
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="short">press CTRL + [enter or left]</pre>

(Just a side note: The keycode for the left arrow is 37)

Check out more information on MouseEvent.ctrlKey

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What's the best way to include php variables in this Javascript code?

I'm currently in the process of constructing a straightforward news page that utilizes ajax filters based on the user's selected category. The javascript code below establishes a connection with a php file and generates HTML using data from a mys ...

What is the best way to send a React prop that is buried deep within a JSON structure?

Currently, I am in the process of creating a product table to showcase items for a store. The headers of this table include: id, title, imagePath, newPrice, oldPrice. To accomplish this, I have developed an ItemTable component within my React application t ...

utilizing React JS to consolidate identical values within an array

I have an array with different data sets const MyArray = [{name: "vehicle", data: [{y: 500, x: '2022-12-12'}, {y: 700, x: '2022-12-12'}]}, {name: "medical", data: [{y: 500, x: '2030-10-12'}, {y: 700, x: '2040-12-12'} ...

Interaction between Jquery and local server

Having some trouble communicating with a local Java server using a jQuery post method. Here is the code I am using: $.post('localhost:5051/receive', {'plugs':client['plugins']}); where client['plugins'] contain ...

What is the best way to conceal the standard 'X' close button within a magnific popup interface?

I implemented the Magnific-popup plugin in my jsp to show messages to users. Here is the code I used to open Magnific Popup: $.magnificPopup.open({ items: { type: 'inline', src: '#idOfSomeDivInPage' }, focus: '#some ...

Socket.io encounters emitting issue within express app.post function

I am working on integrating an express application with a frontend React application using socket connections. My goal is to trigger an event on the connected socket whenever a post request containing JSON data is sent to my server. However, I am facing a ...

Placing a Fresh Item into a Designated Slot within an Array

Imagine having a MongoDB collection that consists of an array of objects being retrieved from an Angular Resource. [{_id: "565ee3582b8981f015494cef", button: "", reference: "", text: "", title: "", …}, {_id: "565ee3582b8981f015494cf0", button: "", ref ...

Which is Better: Lazy Loading, Combining and Minifying, or Using a CDN for Javascript in Angular

When is it advisable to utilize a CDN for loading a JavaScript file? Are there specific files that should be lazy loaded? Additionally, which scripts would benefit from being combined and minified? For instance: jquery + jquery plugins - Should thes ...

Is your div not loading correctly due to JQuery or Javascript?

PHP Version 7.0 JQuery Version 3.1.0 It is noticeable that the content above gets copied and pasted every five seconds instead of refreshing. The aim is to refresh the include every five seconds. Website: Code: <!doctype html> <html><h ...

`The date result is displaying inaccurately`

My JSON result appears incorrect vr_date :Date alert(this.vr_date ) // The result displays Thu Feb 07 2019 00:00:00 GMT+0400 var json = JSON.stringify(this.vr_date); alert(json); // The result displays 2019-02-06T20:00:00.000Z, indicating an issue with ...

Running multiple controller functions in nodejs can be achieved by chaining them together in the desired

Currently, I am working on the boilerplate code of mean.io and adding a password reset email feature to it. Whenever a user requests a password reset with their email as a parameter, I generate a unique salt (resetid) and send them an email with a link con ...

Extract the value of a text box from within a div using jQuery in PHP

By clicking on the div or a tag, I aim to access the user id stored in the hidden field for each user. <?php foreach($user as $users) {?> <div class="user1"> <a class='inline' href="#inline_content" id="new2" > <img src="&l ...

Attempting to conceal the select input and footer components of the Calendar component within a React application

I am currently working on customizing a DatePicker component in Antd and my goal is to display only the calendar body. Initially, I attempted to use styled components to specifically target the header and footer of the calendar and apply display: none; st ...

a service that utilizes $http to communicate with controllers

My situation involves multiple controllers that rely on my custom service which uses $http. To tackle this issue, I implemented the following solution: .service('getDB', function($http){ return { fn: function(){ return $http({ ...

Display basic HTML content prior to Vue.js initializing

In my application, there is a sidebar with an avatar widget created using Vue.js. The loading time for the widget causes the sidebar to display choppy animation. Is there a method to temporarily replace the Vue app with plain HTML until it finishes loadi ...

using an array as an argument in the filtering function

Is there a way to pass an array to the filter method in JavaScript? I have successfully filtered an array using another array. However, my filter array currently has a global scope. How can I pass the array to make my code cleaner? var array = [1, 2, 3, ...

Are there any jQuery Context Menu plugins clever enough to handle window borders seamlessly?

After reviewing UIkit, as well as some other jQuery Context Menu plugins, I have noticed that they all tend to exhibit a similar behavior: The actual menu div renders outside the window, causing valuable content to be hidden from view. Is there a way to ...

Using AngularJS - Injecting a variable into a directive's callback function

I need help with passing arguments from my directive to the caller. I've been struggling to make it work. Currently, I am able to call the function without any arguments successfully. However, when I try to pass arguments, it stops working: Here is ...

Autocomplete feature in Angular not showing search results

I am currently using ng-prime's <p-autocomplete> to display values by searching in the back-end. Below is the HTML code I have implemented: <p-autoComplete [(ngModel)]="agent" [suggestions]="filteredAgents" name="agents" (completeMethod)="f ...

SSL handshake failed - Troubleshooting Socket.io and Node.js connection issues

I am currently working with the Node.js server and utilizing Socket.io to manage connections via Socket. However, I am facing an issue with the SSL certificate. Many users can access the Node.js server without any issues, but there are some users who encou ...