Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i want to detect ctrl + a key if pressed in textbox.

i am using onkeydown event of javascript to detect keys pressed
for single key it works fine but for multiple keys it is not suitable method because it is called immediately when i press a key.

any one guide me what should i do am i using wrong function or is there server side function exists for this.

any help would be appreciated.
Ryan Zahra 8-Mar-11 6:58am    
What do you want to do exactly?
mr_muskurahat 8-Mar-11 7:08am    
actually i have created numeric textbox in which i have restricted all alphabets and special characters and etc.... using onkeydown event now i want to allow ctrl+a to select written data in it. got my point?

private void textBox1_KeyDown(object sender, KeyEventArgs e)
    if (e.Control == true)
          //(int) 'A' = 65  
          //(int) 'a' = 97
          if (e.KeyValue.Equals((int)'A') || e.KeyValue.Equals((int)'a'))
                 textBox1.Text = "Pressed";
Share this answer
Share this answer
I've developped somthing like that, wich can help you

<Script type="text/javascript">
function getPressedKeysCode(obj)
    //In textbox we don't capture the event for backspace and delete button who are used to delete text
   if(event.keyCode != 8 && event.keyCode != 46)
        var text = "";
        var value="";
        if(event.ctrlKey || event.ctrlLeft)
            text  = "ctrl";
        if(event.shiftKey || event.shiftKey)
            text  += ((text !="")?"+":"")+"shift";
        if(event.altKey || event.altLeft)
            text  += ((text !="")?"+":"")+"alt";
        if(event.keyCode && (event.keyCode == 13/*ENTER KEY*/ || (event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 112 && event.keyCode <= 123))) {

            if (event.keyCode == 13)
                text += ((text !="")?"+":"")+"Enter";
            else if (event.keyCode >= 65 && event.keyCode <= 90)
                text += ((text !="")?"+":"")+String.fromCharCode(event.keyCode);
                text += ((text !="")?"+":"")+"F"+(event.keyCode-111);
        obj.value =  text;
        event.returnValue= false;
        event.cancelBubble = true;

<input type="text" onkeydown="getPressedKeysCode(this)">
Share this answer
Mouadh TRABELSI 11-Mar-11 11:29am    
This exemple work with IE, I have not test it on other browsers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900