<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hayr Hotoca</title>
    <description>The latest articles on DEV Community by Hayr Hotoca (@hayrhotoca).</description>
    <link>https://dev.to/hayrhotoca</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2679449%2F3e639c08-7a31-47e5-a5d4-2df4824d36eb.jpeg</url>
      <title>DEV Community: Hayr Hotoca</title>
      <link>https://dev.to/hayrhotoca</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hayrhotoca"/>
    <language>en</language>
    <item>
      <title>How to Convert Short URLs to Long URLs in JavaScript Using Axios or Fetch</title>
      <dc:creator>Hayr Hotoca</dc:creator>
      <pubDate>Thu, 16 Jan 2025 11:31:17 +0000</pubDate>
      <link>https://dev.to/hayrhotoca/how-to-convert-short-urls-to-long-urls-in-javascript-using-axios-or-fetch-48e6</link>
      <guid>https://dev.to/hayrhotoca/how-to-convert-short-urls-to-long-urls-in-javascript-using-axios-or-fetch-48e6</guid>
      <description>&lt;p&gt;Converting short URLs to long URLs can be a common task in web development, especially when dealing with redirects. In this post, we'll explore how to achieve this using JavaScript with two popular libraries: Axios and Fetch API. We'll demonstrate how to retrieve the full URL from a shortened TikTok link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using Axios
&lt;/h2&gt;

&lt;p&gt;Axios is a promise-based HTTP client for the browser and Node.js. Below is a simple example of how to use Axios to convert a short URL to its long form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios("https://vt.tiktok.com/ZS6yXCpvq/")
  .then(res =&amp;gt; console.log(`Full URL with Axios: ${res.request.res.responseUrl}`))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;// Full URL with Axios: &lt;a href="https://www.tiktok.com/@bigthink/video/7345607663322926366" rel="noopener noreferrer"&gt;https://www.tiktok.com/@bigthink/video/7345607663322926366&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We initiate a GET request to the short URL using axios().&lt;/li&gt;
&lt;li&gt;Upon success, the response object contains a property res.request.res.responseUrl that holds the full URL after following any redirects.&lt;/li&gt;
&lt;li&gt;If there’s an error during the request, it will be caught in the catch block, and we log the error message.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Using Fetch
&lt;/h2&gt;

&lt;p&gt;The Fetch API provides a more modern way to make network requests. Here’s how you can use it to achieve the same result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fetch("https://vt.tiktok.com/ZS6yXCpvq/")
  .then(res =&amp;gt; console.log(`Full URL with Fetch: ${res.url}`))
  .catch(err =&amp;gt; console.error(err));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;// Full URL with Fetch: &lt;a href="https://www.tiktok.com/@bigthink/video/7345607663322926366" rel="noopener noreferrer"&gt;https://www.tiktok.com/@bigthink/video/7345607663322926366&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The fetch() function initiates a request to the specified URL.&lt;/li&gt;
&lt;li&gt;The res.url property contains the final URL after any redirects.&lt;/li&gt;
&lt;li&gt;Similar to Axios, errors are handled in the catch block.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both Axios and Fetch provide straightforward methods for converting short URLs to long URLs in JavaScript. While Axios may offer additional features like interceptors and automatic JSON data transformation, Fetch is built into modern browsers and is quite powerful for basic requests. Depending on your project requirements, you can choose either method for handling URL redirection.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>node</category>
    </item>
    <item>
      <title>Build a Secure Password Generator with Javascript</title>
      <dc:creator>Hayr Hotoca</dc:creator>
      <pubDate>Wed, 15 Jan 2025 11:21:07 +0000</pubDate>
      <link>https://dev.to/hayrhotoca/build-a-secure-password-generator-with-javascript-41nl</link>
      <guid>https://dev.to/hayrhotoca/build-a-secure-password-generator-with-javascript-41nl</guid>
      <description>&lt;p&gt;In today's digital world, having a strong password is crucial for safeguarding your online accounts. In this post, I'll walk you through creating a simple yet effective password generator using JavaScript. This generator allows users to customize their password by selecting various criteria such as length, and the inclusion of uppercase letters, lowercase letters, numbers, and symbols.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Code Breakdown
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;HTML Structure&lt;/strong&gt;&lt;br&gt;
Before diving into the JavaScript code, let’s set up the HTML structure for our password generator. Here’s a basic template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Password Generator&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="styles.css"&amp;gt; &amp;lt;!-- Add your CSS file --&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Password Generator&amp;lt;/h1&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;label for="lengthSlider"&amp;gt;Password Length: &amp;lt;span id="lengthValue"&amp;gt;12&amp;lt;/span&amp;gt;&amp;lt;/label&amp;gt;
        &amp;lt;input type="range" id="lengthSlider" min="8" max="20" value="12"&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;input type="checkbox" id="uppercase" checked&amp;gt; Include Uppercase Letters
        &amp;lt;input type="checkbox" id="lowercase" checked&amp;gt; Include Lowercase Letters
        &amp;lt;input type="checkbox" id="numbers" checked&amp;gt; Include Numbers
        &amp;lt;input type="checkbox" id="symbols"&amp;gt; Include Symbols
    &amp;lt;/div&amp;gt;
    &amp;lt;button onclick="generatePassword()"&amp;gt;Generate Password&amp;lt;/button&amp;gt;
    &amp;lt;input type="text" id="passwordOutput" readonly&amp;gt;
    &amp;lt;button class="fa-copy" onclick="copyPassword()"&amp;gt;Copy&amp;lt;/button&amp;gt;

    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;!-- Link to your JavaScript file --&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  JavaScript Functionality
&lt;/h2&gt;

&lt;p&gt;Now, let’s dive into the JavaScript code that powers our password generator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function generatePassword() {
    const length = document.getElementById('lengthSlider').value;
    const uppercase = document.getElementById('uppercase').checked;
    const lowercase = document.getElementById('lowercase').checked;
    const numbers = document.getElementById('numbers').checked;
    const symbols = document.getElementById('symbols').checked;

    let chars = '';
    if (uppercase) chars += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    if (lowercase) chars += 'abcdefghijklmnopqrstuvwxyz';
    if (numbers) chars += '0123456789';
    if (symbols) chars += '!@#$%^&amp;amp;*()_+-=[]{}|;:,.&amp;lt;&amp;gt;?';

    let password = '';
    for (let i = 0; i &amp;lt; length; i++) {
        password += chars.charAt(Math.floor(secureRandom() * chars.length));
    }

    document.getElementById('passwordOutput').value = password;
}

function secureRandom() {
    try {
        const array = new Uint8Array(8);
        const buf = window.crypto.getRandomValues(array);
        const offset = Math.random() &amp;lt; 0.5 ? 0 : buf.length - 4;
        const dataView = new DataView(buf.buffer);
        const intVal = dataView.getUint32(offset, true); // Convert bytes to an unsigned 32-bit integer
        const normalized = intVal / (Math.pow(2, 32) - 1); // Scale to [0, 1)
        return normalized;
    } catch (error) {
        console.error("Error generating secure random number:", error);
        throw error; // Rethrow or handle as needed
    }
}

function copyPassword() {
    const passwordOutput = document.getElementById('passwordOutput');
    passwordOutput.select();
    document.execCommand('copy');

    // Add visual feedback
    const btn = document.querySelector('.fa-copy').parentElement;
    btn.innerHTML = '&amp;lt;i class="fas fa-check"&amp;gt;&amp;lt;/i&amp;gt;';
    setTimeout(() =&amp;gt; {
        btn.innerHTML = '&amp;lt;i class="fas fa-copy"&amp;gt;&amp;lt;/i&amp;gt;';
    }, 1000);
}

// Update length value display
document.getElementById('lengthSlider').addEventListener('input', function () {
    document.getElementById('lengthValue').textContent = this.value;
});

// Generate initial password
generatePassword();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation of Key Functions
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;generatePassword()&lt;/code&gt;: This function collects user preferences from the UI and constructs a character set based on the selected options. It then generates a random password by selecting characters from this set.&lt;br&gt;
&lt;code&gt;secureRandom()&lt;/code&gt;: This function uses the Web Crypto API to generate secure random numbers, ensuring that the passwords generated are not only random but also secure.&lt;br&gt;
&lt;code&gt;copyPassword()&lt;/code&gt;: This function allows users to easily copy the generated password to their clipboard and provides visual feedback to confirm the action.&lt;br&gt;
&lt;code&gt;Event Listener for Length Slider&lt;/code&gt;: This updates the displayed password length dynamically as the user adjusts the slider.&lt;/p&gt;

&lt;p&gt;The final product: &lt;a href="https://1limx.com/password-generator" rel="noopener noreferrer"&gt;https://1limx.com/password-generator&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With just a few lines of code, you can create a robust and customizable password generator that enhances your online security. Feel free to expand upon this project by adding more features or improving the user interface! Happy coding! If you have any questions or suggestions for improvements, feel free to leave a comment below!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Create Stunning Gradual Div Reveals with JavaScript setTimeout and CSS Transitions</title>
      <dc:creator>Hayr Hotoca</dc:creator>
      <pubDate>Tue, 14 Jan 2025 11:32:27 +0000</pubDate>
      <link>https://dev.to/hayrhotoca/create-stunning-gradual-div-reveals-with-javascript-settimeout-and-css-transitions-2mlo</link>
      <guid>https://dev.to/hayrhotoca/create-stunning-gradual-div-reveals-with-javascript-settimeout-and-css-transitions-2mlo</guid>
      <description>&lt;p&gt;Creating a smooth and engaging user experience on the web often involves combining JavaScript and CSS transitions. In this post, we will explore how to use the setTimeout function in JavaScript to gradually reveal elements on a webpage with CSS transitions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The goal of this example is to create a series of div elements that fade in one after the other. We will leverage the setTimeout function to control the timing of each element's appearance, while CSS transitions will handle the visual effects.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Structure
&lt;/h2&gt;

&lt;p&gt;We will start by defining our HTML structure. Here’s a simple layout with several divs containing images and links:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Gradual Div Reveal&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="src/style.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="toggle-div"&amp;gt;
      &amp;lt;img src="https://aws.amazon.com/startups/upload/e4d8d468-90d1-704f-a34e-7e195ce4025a/ceac2e85-dca6-4da4-bbf7-359df7db739d.png" /&amp;gt;
      &amp;lt;a href=""&amp;gt;perplexity.com&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="toggle-div"&amp;gt;
      &amp;lt;img src="https://aimode.co/wp-content/uploads/2024/07/meta-ai-logo.webp" /&amp;gt;
      &amp;lt;a href=""&amp;gt;meta.ai&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="toggle-div"&amp;gt;
      &amp;lt;img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Microsoft_365_Copilot_Icon.svg/2048px-Microsoft_365_Copilot_Icon.svg.png" /&amp;gt;
      &amp;lt;a href=""&amp;gt;copilot.microsoft.com&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="toggle-div"&amp;gt;
      &amp;lt;img src="https://www.deepseek.com/favicon.ico" /&amp;gt;
      &amp;lt;a href=""&amp;gt;chat.deepseek.com&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="toggle-div"&amp;gt;
      &amp;lt;img src="https://uxwing.com/wp-content/themes/uxwing/download/brands-and-social-media/google-gemini-icon.png" /&amp;gt;
      &amp;lt;a href=""&amp;gt;gemini.google.com&amp;lt;/a&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="src/script.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  CSS for Transitions
&lt;/h2&gt;

&lt;p&gt;Next, we will define the CSS styles that will control the appearance and transition effects of our divs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.toggle-div {
  opacity: 0; /* Start hidden */
  transition: opacity 1s ease; /* Transition effect */
  height: 50px; /* Set a height for visibility */
  background-color: lightblue; /* Background color for visibility */
  margin: 10px 0; /* Spacing between divs */
  padding: 12px 80px;
  display: flex;
  align-items: center;
}

.toggle-div img {
  height: 100%;
  margin-right: 8px;
}

.toggle-div a {
  font-size: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation of CSS
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Opacity&lt;/strong&gt;: Initially set to 0, making the divs invisible.&lt;br&gt;
&lt;strong&gt;Transition&lt;/strong&gt;: The opacity property will transition over 1 second with an ease effect.&lt;br&gt;
&lt;strong&gt;Styling&lt;/strong&gt;: Basic styling is applied to ensure visibility and layout.&lt;/p&gt;
&lt;h2&gt;
  
  
  JavaScript for Gradual Reveal
&lt;/h2&gt;

&lt;p&gt;Finally, we will implement the JavaScript logic to control when each div becomes visible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// JavaScript to reveal divs
const divs = document.querySelectorAll('.toggle-div');

divs.forEach((div, index) =&amp;gt; {
  setTimeout(() =&amp;gt; {
    div.style.opacity = 1; // Change opacity to make it visible
  }, index * 500); // Delay each div by half a second multiplied by its index
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation of JavaScript
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Query Selector&lt;/strong&gt;: We select all elements with the class .toggle-div.&lt;br&gt;
&lt;strong&gt;forEach Loop&lt;/strong&gt;: We iterate over each selected div.&lt;br&gt;
&lt;strong&gt;setTimeout&lt;/strong&gt;: For each div, we set a timeout that changes its opacity to 1, making it visible. The delay increases with each iteration, creating a staggered reveal effect.&lt;/p&gt;

&lt;p&gt;Here is the final product:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafw5zie2zhqswfgpsviq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fafw5zie2zhqswfgpsviq.png" alt="Image description" width="800" height="910"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check it out: &lt;a href="https://playcode.io/2219619" rel="noopener noreferrer"&gt;https://playcode.io/2219619&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By combining JavaScript's setTimeout function with CSS transitions, we can create visually appealing effects that enhance user interaction. This approach is not only simple but also effective in providing a polished feel to web applications.&lt;br&gt;
Feel free to experiment with different timings and styles to see how they affect the overall user experience!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Detecting Key Combinations Press in JavaScript</title>
      <dc:creator>Hayr Hotoca</dc:creator>
      <pubDate>Mon, 13 Jan 2025 08:57:57 +0000</pubDate>
      <link>https://dev.to/hayrhotoca/detecting-key-combinations-press-in-javascript-5g90</link>
      <guid>https://dev.to/hayrhotoca/detecting-key-combinations-press-in-javascript-5g90</guid>
      <description>&lt;p&gt;Capturing a single key press in JavaScript is a straightforward task, but when it comes to detecting multiple key combinations, things can get a bit trickier. In this post, we'll explore a simple implementation that captures the "Command" key and its combinations with "C" (for copy) and "V" (for paste). We'll also discuss how to extend this functionality to detect more complex key combinations.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basic Setup
&lt;/h2&gt;

&lt;p&gt;Here's a simple code snippet that demonstrates how to capture the "Command" key and its combinations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const keyState = {
  cmd: false,
};

// Add event listeners for keydown and keyup events
window.addEventListener("keydown", handleKeyDown);
window.addEventListener("keyup", handleKeyUp);

// Function to handle keydown events
function handleKeyDown(event) {
  if (event.key === "Meta") {
    keyState.cmd = true;
  }
  // Check for the Command and c combination
  if (keyState.cmd &amp;amp;&amp;amp; event.key === "c") {
    console.log("user wants to copy");
  }
  // Check for the Command and v combination
  if (keyState.cmd &amp;amp;&amp;amp; event.key === "v") {
    console.log("user wants to paste");
  }
}

// Function to handle keyup events
function handleKeyUp(event) {
  if (event.key === "Meta") {
    keyState.cmd = false;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Key State Tracking&lt;/strong&gt;: We maintain a simple keyState object to track whether the "Command" key is pressed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Event Listeners&lt;/strong&gt;: We add event listeners for keydown and keyup events to detect when keys are pressed or released.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Combination Detection&lt;/strong&gt;: In the handleKeyDown function, we check if the "Command" key is held down while another specific key (like "C" or "V") is pressed.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Extending Functionality: Detecting More Key Combinations
&lt;/h2&gt;

&lt;p&gt;While our initial implementation works well for detecting just two combinations, you might want to expand it to include more keys or even complex combinations. Here’s how you can do that:&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Expand the Key State Object
&lt;/h2&gt;

&lt;p&gt;You can add more keys to your keyState object. For example, let’s add support for Shift and Alt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const keyState = {
  cmd: false,
  shift: false,
  alt: false,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Update Event Handlers
&lt;/h2&gt;

&lt;p&gt;Modify your event handlers to track these additional keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleKeyDown(event) {
  if (event.key === "Meta") {
    keyState.cmd = true;
  }
  if (event.key === "Shift") {
    keyState.shift = true;
  }
  if (event.key === "Alt") {
    keyState.alt = true;
  }

  // Example of detecting Command + Shift + C
  if (keyState.cmd &amp;amp;&amp;amp; keyState.shift &amp;amp;&amp;amp; event.key === "c") {
    console.log("user wants to copy with Shift");
  }

  // Example of detecting Command + Alt + V
  if (keyState.cmd &amp;amp;&amp;amp; keyState.alt &amp;amp;&amp;amp; event.key === "v") {
    console.log("user wants to paste with Alt");
  }
}

function handleKeyUp(event) {
  if (event.key === "Meta") {
    keyState.cmd = false;
  }
  if (event.key === "Shift") {
    keyState.shift = false;
  }
  if (event.key === "Alt") {
    keyState.alt = false;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Test Your Combinations
&lt;/h2&gt;

&lt;p&gt;Now you can test various combinations like:&lt;br&gt;
&lt;strong&gt;Command + C&lt;/strong&gt; for copy&lt;br&gt;
&lt;strong&gt;Command + V&lt;/strong&gt; for paste&lt;br&gt;
&lt;strong&gt;Command + Shift + C&lt;/strong&gt; for a different action&lt;br&gt;
&lt;strong&gt;Command + Alt + V&lt;/strong&gt; for another action&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Detecting single key presses in JavaScript is easy, but as you start combining multiple keys, it requires a bit more thought and implementation. By maintaining a state object for your keys, you can effectively track multiple combinations and respond accordingly.&lt;br&gt;
Feel free to experiment with the code above and extend it further! What other combinations would you like to implement? Share your thoughts in the comments below!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
