0

Suppose I have a 2D array. It has four rows and four columns. Now I want that initially I place some marker in the array at some location. Say, array[x][y] = 1 -> marker. I want to move this marker in the array in 8 dimensions by using buttons. Like, on up, location is [x-1][y]. Down is [x+1][y]. Left is [x][y-1]. And right is [x][y+1]. Now I have my logic that this is how I will do it!

1st Question: How to associate my buttons of up down sideways to move in the array?

2nd Question: How will I tackle the other four dimensions as I'll be using two buttons for other complex 4 changing location as <^ two buttons are pressed and location now is [x-1][y-1]!

Kindly direct me or help me with the button associations.

aib
  • 45,516
  • 10
  • 73
  • 79
Plotter
  • 39
  • 1
  • 3
  • 12

1 Answers1

0

You can use a keyboard hook to trigger your logic when the arrow keys are pressed. You would define a callback function containing code like:

if (  WM_KEYDOWN == wParam && VK_UP == lParam )
    //do up logic
else if ( WM_KEYDOWN == wParam && VK_DOWN == lParam )
    //do down logic
else if ....

For the diagonal buttons, you can use the home, pgup, pgdn, and end keys on the numeric keypad of the keyboard (this would require a keyboard with numeric keypad). These buttons correspond to the arrow combinations like <^, and would keep the implementation simple.

For information on how to use a keyboard hook, see this post: C++ Win32 keyboard events

For list of virtual key codes (ie VK_UP) see this link: http://msdn.microsoft.com/en-us/library/ms927178.aspx

Community
  • 1
  • 1
ryan0
  • 1,482
  • 16
  • 21