Click here to Skip to main content
15,893,622 members
Home / Discussions / C#
   

C#

 
AnswerRe: Just A Thought - Interface = I, Abstract = A Pin
PIEBALDconsult29-Oct-10 18:05
mvePIEBALDconsult29-Oct-10 18:05 
AnswerRe: Just A Thought - Interface = I, Abstract = A Pin
Abhinav S30-Oct-10 18:19
Abhinav S30-Oct-10 18:19 
GeneralRe: Just A Thought - Interface = I, Abstract = A Pin
thatraja1-Nov-10 21:18
professionalthatraja1-Nov-10 21:18 
QuestionSending parameters to an appilcation if it is open. Pin
TheFoZ29-Oct-10 2:53
TheFoZ29-Oct-10 2:53 
QuestionKeys and Disabling Pin
SRJ9229-Oct-10 2:11
SRJ9229-Oct-10 2:11 
AnswerRe: Keys and Disabling Pin
OriginalGriff29-Oct-10 2:18
mveOriginalGriff29-Oct-10 2:18 
AnswerRe: Keys and Disabling Pin
Sherylee29-Oct-10 2:30
Sherylee29-Oct-10 2:30 
AnswerRe: Keys and Disabling Pin
Ian Shlasko29-Oct-10 3:21
Ian Shlasko29-Oct-10 3:21 
Don't mean to step on the other guys who answered, but it looks like you're trying to have Up and Down cancel each other out (And Left+Right)... This'll take a little more than what you have now, but not very much.

The easiest way would probably be to just keep track of which keys are currently pressed. Now, you can use API calls to query them directly, but if you want to stick to simple events, here's one way to do it:

1) Create a dictionary mapping keys to a boolean

2) Whenever a key you're watching is pressed OR released (Handle the KeyUp event too!), set its value in that dictionary to true (Pressed) or false (Not pressed)... If you want to make this more readable and intuitive, you can even use an enum instead of a boolean.

3) Whenever you make a change to the dictionary, run a separate function to test the current key states... Then you can check for things like if (IsKeyPressed[Keys.Left] && !IsKeyPressed[Keys.Right])...

There are plenty of other ways to do this, but this is one of the simplest... If you want to be more efficient, you can use a single flags-type enum value instead of a dictionary, and use binary operations to set and unset the various components:
[Flags]
enum ArrowKeyStates {
  None = 0,

  Left = 1,
  Up = 2,
  Right = 4,
  Down = 8,

  // Then a few more to make testing for diagonals easy...
  UpLeft = 3,
  UpRight = 6,
  DownLeft = 9,
  DownRight = 12
}

// To set a key as pressed, use a binary OR:
MyKeyState |= ArrowKeyStates.Left;

// To set a key as released, use a binary XOR:
MyKeyState ^= ArrowKeyStates.Left;

Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)

AnswerRe: Keys and Disabling Pin
SRJ9229-Oct-10 4:55
SRJ9229-Oct-10 4:55 
QuestionCrystal Report Formating Pin
Nikhil Bhivgade28-Oct-10 23:39
professionalNikhil Bhivgade28-Oct-10 23:39 
AnswerRe: Crystal Report Formating Pin
Richard MacCutchan29-Oct-10 1:38
mveRichard MacCutchan29-Oct-10 1:38 
AnswerRe: Crystal Report Formating Pin
RaviRanjanKr29-Oct-10 3:41
professionalRaviRanjanKr29-Oct-10 3:41 
GeneralRe: Crystal Report Formating Pin
Nikhil Bhivgade29-Oct-10 23:05
professionalNikhil Bhivgade29-Oct-10 23:05 
GeneralRe: Crystal Report Formating Pin
Mubeen.asim3-Nov-10 0:03
Mubeen.asim3-Nov-10 0:03 
QuestionStandard Input & Output Pin
AliAmjad28-Oct-10 21:27
AliAmjad28-Oct-10 21:27 
AnswerRe: Standard Input & Output Pin
PIEBALDconsult29-Oct-10 3:23
mvePIEBALDconsult29-Oct-10 3:23 
QuestionOn server master page is not running Pin
Mansi Arora28-Oct-10 20:23
Mansi Arora28-Oct-10 20:23 
AnswerRe: On server master page is not running Pin
abinmaths28-Oct-10 20:46
abinmaths28-Oct-10 20:46 
GeneralRe: On server master page is not running Pin
Mycroft Holmes28-Oct-10 22:22
professionalMycroft Holmes28-Oct-10 22:22 
GeneralRe: On server master page is not running Pin
OriginalGriff28-Oct-10 23:05
mveOriginalGriff28-Oct-10 23:05 
AnswerRe: On server master page is not running Pin
#realJSOP28-Oct-10 23:46
mve#realJSOP28-Oct-10 23:46 
AnswerRe: On server master page is not running Pin
Ravi Sant14-Apr-11 23:21
Ravi Sant14-Apr-11 23:21 
Questionproblem related to "Nural networks face detection algprithm" Pin
inayathussaintoori28-Oct-10 10:02
inayathussaintoori28-Oct-10 10:02 
AnswerRe: problem related to "Nural networks face detection algprithm" Pin
dan!sh 28-Oct-10 10:07
professional dan!sh 28-Oct-10 10:07 
AnswerRe: problem related to "Nural networks face detection algprithm" Pin
Dave Kreskowiak28-Oct-10 10:14
mveDave Kreskowiak28-Oct-10 10:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.