# Selecting buttons with arrow keys

**URL:** <https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089>\
**Category:** General\
**Created:** [December 9, 2017, 4:02pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089 "2017-12-09T16:02:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maurits\_Woudenberg](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Maurits\_Woudenberg](https://forum.xojo.com/u/Maurits_Woudenberg)\
**Post date:** [December 9, 2017, 4:02pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/1 "2017-12-09T16:02:31Z")

</div>

Hi,

I’m making a virtual QWERTY keyboard that is to be controlled with a joystick. I use an arduino Leonardo to convert the joystick movement to arrow key presses for selecting, and keypress for inputting. I made push buttons for each letter that add their letter to a string. I arranged the tab order of the buttons to scroll through the keyboard with the arrow keys (joystick) but I can only go left and right. I can’t jump the lines like: is selected -\> press to select (which is the button directly above ). Instead of going up it just goes back one step in the tab order so ~~is selected.~~

 

How do I solve this problem?

Many thanks!

Maurits

PS. Another minor thing: what action should a button perform to delete the last letter of a string, like is pressed?

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [December 9, 2017, 4:05pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/2 "2017-12-09T16:05:00Z")

</div>

without knowing how you are doing what you are doing, there is no way anyone can suggest a fix or change to you…  
is this even Xojo related?

---

<div class="post-metadata">

**Author:** ![Maurits\_Woudenberg](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Maurits\_Woudenberg](https://forum.xojo.com/u/Maurits_Woudenberg)\
**Post date:** [December 9, 2017, 4:40pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/3 "2017-12-09T16:40:09Z")

</div>

> [@](#):
>
> …without knowing how you are doing…

I’m doing very well, thank you. What about yourself, sir?

> [@](#):
>
> is this even Xojo related?

Very much!

To make it more simple, I need to select the Xojo bushbuttons (.setFocus?) with the arrows keys. Since I have many pushbuttons on the screen I would like to be able to select them by pressing the up/down/left/right keys to navigate though them, rather then only going up and down the tab order. Does that clarify it a little?

---

<div class="post-metadata">

**Author:** ![anon20074439](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@anon20074439](https://forum.xojo.com/u/anon20074439)\
**Post date:** [December 9, 2017, 5:00pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/4 "2017-12-09T17:00:18Z")

</div>

PushButtons are moved through in the other that they are placed on the window. The OS doesnt know the relative position of the controls so it doesnt know that up will skip a few controls and go to the “row” above or off the “top row” and onto the “bottom row”.

You could do this by creating a mapping between keys currently on and what key you want to end up on when you press each of the cardinal directions (NSEW) when on a letter. Then, when you select the up sick movement on H for example, it will know to move to Y. Then you select that manually using PushButton.SetFocus for the Y PushButton.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [December 9, 2017, 5:03pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/5 "2017-12-09T17:03:51Z")

</div>

> [@363929:@Maurits Woudenberg](#):
>
> I’m doing very well, thank you. What about yourself, sir?

that didn’t help much now did it?

---

<div class="post-metadata">

**Author:** ![anon20074439](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/ac8455/32.png) [@anon20074439](https://forum.xojo.com/u/anon20074439)\
**Post date:** [December 9, 2017, 5:19pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/6 "2017-12-09T17:19:03Z")

</div>

> [@363914:@Maurits Woudenberg](#):
>
> PS. Another minor thing: what action should a button perform to delete the last letter of a string, like is pressed?

Are you inputting them into a textfield on the virtual keyboard window or are you using some other method to send the keypresses to your active app?

Depending on what you’re doing determines the information we can provide to assist you. I.e. if its just an internal string, you can remove one character off the end of it using left(len(myString)-1)

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [December 9, 2017, 5:54pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/7 "2017-12-09T17:54:35Z")

</div>

> [@](#):
>
> I use an arduino Leonardo to convert the joystick movement to arrow key presses for selecting,

So the tab order isnt really relevant.  
In fact, what you see on screen doesnt even need to be a button, does it?  
A canvas with letters on it would be fine.

Imagine the letters are held in an array of (say) 10 across and 3 down  
first row of letters would be ‘row 0’

Q W E R T Y…  
A S D F G H…  
Z X C V B

No-one will likely object if the letters appear in this regular grid form, rather than a conventional ‘shifted’ keyboard layout of  
Q W E R T Y  
A S D F G  
Z X C V

But if you detect the arrow keys, you can amend your X, Y numbers by adding or subtracting one.  
The selected letter would be LetterArray(x,y)  
Detect ENTER and you add the letter from the array

To type SEAT, starting at 1,1  
ENTER (gets A)  
UP ,RIGHT changes the array to 2,0 by subtracting 1 from the Y, and adding 1 to the X  
ENTER (gets E)  
DOWN,LEFT,LEFT adds 1 to Y, and subtracts 2 from X… ENTER adds A from array (0,1)

and so on.

You can refresh the display after each movement. Paint the selected color in a special color, and all the others in a plain color.

---

<div class="post-metadata">

**Author:** ![Maurits\_Woudenberg](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Maurits\_Woudenberg](https://forum.xojo.com/u/Maurits_Woudenberg)\
**Post date:** [December 9, 2017, 6:57pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/8 "2017-12-09T18:57:17Z")

</div>

Many thanks all of you!

Have a good weekend!

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:01pm UTC](https://forum.xojo.com/t/selecting-buttons-with-arrow-keys/41089/9 "2020-10-29T19:01:33Z")

</div>


