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. How do i check if the Left Shift key was pressed?

How do i check if the Left Shift key was pressed?

Scheduled Pinned Locked Moved C#
question
2 Posts 2 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.
  • C Offline
    C Offline
    CyberKewl
    wrote on last edited by
    #1

    I tried using this code : if ((Control.ModifierKeys & Keys.LShiftKey) == Keys.LShiftKey) and a few other combinations but it doesn't work. I can detect just the shift key being pressed but i want to detect if the LEFT shift key (which is more specific) being pressed. Is there any way?

    D 1 Reply Last reply
    0
    • C CyberKewl

      I tried using this code : if ((Control.ModifierKeys & Keys.LShiftKey) == Keys.LShiftKey) and a few other combinations but it doesn't work. I can detect just the shift key being pressed but i want to detect if the LEFT shift key (which is more specific) being pressed. Is there any way?

      D Offline
      D Offline
      dynamic
      wrote on last edited by
      #2

      both shift keys ( the one on the left of the keyboard and the one on the right ) hold the same value "16" so no way to tell , but if you wish to catch events such as the up / down arrows etc... you can do something like this : C#:


      private void Form1_Load(object sender, System.EventArgs e)
      {
      this.KeyPreview=true;
      }
      // set keypreview on.
      ///////////////////
      protected override bool ProcessKeyPreview(ref System.Windows.Forms.Message m)
      {
      switch (m.WParam.ToInt32())
      {
      case 38: // up arrow key
      MessageBox.Show("you clicked UP!");
      break;
      case 40: // down arrow key
      MessageBox.Show("you clicked DOWN!");
      break;
      case 37: // left arrow key
      MessageBox.Show("you clicked LEFT!");
      break;
      case 39: // right arror key
      MessageBox.Show("you clicked RIGHT!");
      break;
      }
      return true;
      }


      hope it helps. Vb:


      Public Function TwinsOnWay(ByVal twins As String) As String
      Select Case twins
      Case "Gender"
      Return "Two Girls"
      End Select
      End Function


      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