Affichage des articles dont le libellé est KeyChar. Afficher tous les articles
Affichage des articles dont le libellé est KeyChar. Afficher tous les articles

Javascript KeyChar, KeyCode

How To Use Key Char And Key Code In JS

js keycode & keychar


In this JavaScript tutorial, we will explore how to utilize charCode and keyCode on both key press and key down events. With JavaScript programming language and NetBeans editor, you have the ability to easily check the specific key that has been pressed, offering a greater level of control and functionality.


Project Source Code:


<!DOCTYPE html>
<html>
    <head>
        <title>JavaScript: Key Code - Char Code</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body onkeypress="listenKey(event)">
        <script>
            
            function listenKey(event)
            {
                var cd = event.keyCode, ch = event.charCode,val = String.fromCharCode(ch);
                console.log("keyCode = "+cd+" charCode = "+ch + " Value = "+ val);
            }
            
        </script>
    </body>
</html>


Java getKeyChar

Java Using Get Key Char

Java get Key Char

In This Java Tutorial We Will See How To Use getKeyChar On KeyReleased To Display The Clicked Key Text Into a JLabel In Java Programming Language And NetBeans Editor.


Source Code:

private void formKeyReleased(java.awt.event.KeyEvent evt) {                                 
  
        char key = evt.getKeyChar();
        jLabel1.setText(jLabel1.getText()+" "+Character.toString(key));
        
    } 
      
///////////////OUTPUT:

getkeychar using  java




VB.Net KeyChar

VBNET Using Key Char

VBnet Key Char

In This VB.Net Tutorial  We Will See How To Use KeyChar On KeyPress To Check Which Key Is Pressed Like ENTER or SPACE In Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class Form_key_char


    Private Sub Form_key_char_KeyPress(sender As Object, e As KeyPressEventArgs) Handles MyBase.KeyPress

        Dim ch As String
        ch = e.KeyChar

        Label1.Text = ch

        Select Case ch

            Case Convert.ToChar(Keys.Enter)
                Label1.Text = "Enter"

            Case Convert.ToChar(Keys.Space)
                Label1.Text = "Space"

        End Select

    End Sub
End Class
      
///////////////OUTPUT:
vbnet enter key press

vbnet spacebar key press




C# KeyChar, KeyCode

How To Use Key Char And Key Code In C#

C# Key Char & Key Code


In This C# Tutorial  We Will See How To Use KeyChar And KeyCode To Check Which Key Is Pressed ENTER or SPACE, SHIFT... In CSharp Programming Language And Visual  Studio Editor.


Project Source Code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Csharp_keycode_keychar : Form
    {
        public Csharp_keycode_keychar()
        {
            InitializeComponent();
        }

// keycode
        private void Csharp_keycode_keychar_KeyDown(object sender, KeyEventArgs e)
        {

            if ((e.KeyCode == Keys.Enter) && e.Control)
                label1.Text = "CONTROL + ENTER";
            else
                label1.Text = "/////";

        }

// keychar
        private void Csharp_keycode_keychar_KeyPress(object sender, KeyPressEventArgs e)
        {
            
            if(e.KeyChar == (char)Keys.Space)
                label1.Text = "spacebar";
            else
                label1.Text = "/////";
           
        }
    }
}



// OUTPUT :

c# enter key keychar