Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem with keypress function

problem with keypress function

Scheduled Pinned Locked Moved C#
asp-nethelpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MehmetKocc
    wrote on last edited by
    #1

    Hi What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem for ex: when i press alt + f4 i wnat to see alt f4 in the label i have the code snippet

    protected override void OnKeyDown(KeyEventArgs keyEvent)
    {

            label1.Text = "";
            
            label1.Text=keyEvent.KeyCode.ToString();
    
            //while(?)         i wanted to write a while loop for while the key is still pressed(down)
            //label1.Text=keyEvent.KeyCode.ToString()+"+"+label1.Text;
            
        }
    

    Can anyone show me a way to do it please? Thanks...

    M L D R 4 Replies Last reply
    0
    • M MehmetKocc

      Hi What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem for ex: when i press alt + f4 i wnat to see alt f4 in the label i have the code snippet

      protected override void OnKeyDown(KeyEventArgs keyEvent)
      {

              label1.Text = "";
              
              label1.Text=keyEvent.KeyCode.ToString();
      
              //while(?)         i wanted to write a while loop for while the key is still pressed(down)
              //label1.Text=keyEvent.KeyCode.ToString()+"+"+label1.Text;
              
          }
      

      Can anyone show me a way to do it please? Thanks...

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      hmmmm seems suspicious... but I think KeyEventArgs has something to detect if buttons like alt, shift, ctrl are currently pressed.

      Life goes very fast. Tomorrow, today is already yesterday.

      1 Reply Last reply
      0
      • M MehmetKocc

        Hi What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem for ex: when i press alt + f4 i wnat to see alt f4 in the label i have the code snippet

        protected override void OnKeyDown(KeyEventArgs keyEvent)
        {

                label1.Text = "";
                
                label1.Text=keyEvent.KeyCode.ToString();
        
                //while(?)         i wanted to write a while loop for while the key is still pressed(down)
                //label1.Text=keyEvent.KeyCode.ToString()+"+"+label1.Text;
                
            }
        

        Can anyone show me a way to do it please? Thanks...

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        forget the loop, loops seldom belong in an event handler. Create one method that is used for both KeyDown and KeyUp events. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


        1 Reply Last reply
        0
        • M MehmetKocc

          Hi What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem for ex: when i press alt + f4 i wnat to see alt f4 in the label i have the code snippet

          protected override void OnKeyDown(KeyEventArgs keyEvent)
          {

                  label1.Text = "";
                  
                  label1.Text=keyEvent.KeyCode.ToString();
          
                  //while(?)         i wanted to write a while loop for while the key is still pressed(down)
                  //label1.Text=keyEvent.KeyCode.ToString()+"+"+label1.Text;
                  
              }
          

          Can anyone show me a way to do it please? Thanks...

          D Offline
          D Offline
          DoctorMick
          wrote on last edited by
          #4

          Check the value of keyEvent.Alt, it will be true if the alt key is held down.

          1 Reply Last reply
          0
          • M MehmetKocc

            Hi What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem for ex: when i press alt + f4 i wnat to see alt f4 in the label i have the code snippet

            protected override void OnKeyDown(KeyEventArgs keyEvent)
            {

                    label1.Text = "";
                    
                    label1.Text=keyEvent.KeyCode.ToString();
            
                    //while(?)         i wanted to write a while loop for while the key is still pressed(down)
                    //label1.Text=keyEvent.KeyCode.ToString()+"+"+label1.Text;
                    
                }
            

            Can anyone show me a way to do it please? Thanks...

            R Offline
            R Offline
            ramz_g
            wrote on last edited by
            #5

            Hi, You can override the ProcessCmdKey() function in Control class like this : protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Alt | Keys.F4)) { //Your Code } return base.ProcessCmdKey(ref msg, keyData); } Hope this helps, ramz_g :-)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups