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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Get information about serval given keys is pressed?

Get information about serval given keys is pressed?

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 3 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.
  • P Offline
    P Offline
    panyl
    wrote on last edited by
    #1

    I want to process something when keys.control and keys.left are pressed at the same time,so how do i know if them are pressed at the same time? Thanks!(C#)

    G 1 Reply Last reply
    0
    • P panyl

      I want to process something when keys.control and keys.left are pressed at the same time,so how do i know if them are pressed at the same time? Thanks!(C#)

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Detect when the control key is pressed and released and store the status in a variable, so that when the left key gets pressed you can check if the control key is currently pressed.

      Despite everything, the person most likely to be fooling you next is yourself.

      P 1 Reply Last reply
      0
      • G Guffa

        Detect when the control key is pressed and released and store the status in a variable, so that when the left key gets pressed you can check if the control key is currently pressed.

        Despite everything, the person most likely to be fooling you next is yourself.

        P Offline
        P Offline
        panyl
        wrote on last edited by
        #3

        Thanks for you reply! I have solve my question. code: //Onkeydown if(e.KeysData.tostring().contains("Control")&&(e.Keysdata.tostring().contains("Left")) { // do my work; } But i found a erratic thing: if i press keys.left or Right/up/down,it ignore me in function OnKeyDown,OnKeyUp,OnKeyPress; if i press keys.control and keys.left,it will process my work; if i press keys.shift and keys.left,it will ignore me in function OnKeyDown,but process in OnkeyUp; ..... i want to know when will those events occur?Could you help me?

        L 1 Reply Last reply
        0
        • P panyl

          Thanks for you reply! I have solve my question. code: //Onkeydown if(e.KeysData.tostring().contains("Control")&&(e.Keysdata.tostring().contains("Left")) { // do my work; } But i found a erratic thing: if i press keys.left or Right/up/down,it ignore me in function OnKeyDown,OnKeyUp,OnKeyPress; if i press keys.control and keys.left,it will process my work; if i press keys.shift and keys.left,it will ignore me in function OnKeyDown,but process in OnkeyUp; ..... i want to know when will those events occur?Could you help me?

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

          Hi, you can get the instantaneous value of the modifier keys using Control.ModifierKeys so you don't have to track those keys yourself (which you can hardly do correct, say e.g. the CTRL key gets pushed down on one Control, then released above another Form). BTW: don't convert to string for a logical test; instead of if(e.KeysData.tostring().contains("Control"))... you can do: if ((e.KeysData & Keys.Control)==Keys.Control)... or if ((e.KeysData & Keys.Control)!=0)... :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Voting for dummies? No thanks. X|


          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