logo
background
 Home and Links
 Your PC and Security
 Server NAS
 Wargames
 Astronomy
 PhotoStory
 DVD making
 Raspberry Pi
 PIC projects
 Other projects
 Next >>
[The need for a hot-key keypad] [Enter the Pi Zero Keyboard Device] [A DIY keypad] [Where to get the key buttons ?] [Off-the-shelf  keypads] [Hot-key sequences]

The need for a hot-key keypad

The typically modern game can be totally controlled by using your mouse. Typically this involves a Right click to select a unit, a Left click to select 'something' from a menu and then another right-click to indicate a position on-screen. For example, you might move the mouse and left-click to select your 'tank troop', then right-click to open a drop-down menu and then select the 'attack' option and finally, right-click on an enemy unit to set that as the 'target'. However, most RTS (Real Time Strategy) games can usually be controlled by a combination of a 'hot-key' presses plus mouse action. So instead of the the first two mouse clicks, hitting 't' 'a' might select your tank and set 'attack' mode, after which only a single mouse click is needed - on an enemy unit - to set the 'target'. Since you can hit 'ta' whilst moving the mouse towards the enemy target, the use of hot-keys is much faster than using the mouse with menu selection. When two players 'face off', the 'hot-key' user will typically get their shot off first. Indeed, in many RTS games - such as Age of Empires - the hot-key user can operate so much faster than the mouse/menu user that they have an overwhelming advantage. However hot-key users face a number of problems :- 1) First, the hot-keys used are often very badly chosen. 1a) Often the key letter appears arbitary - whilst 't' for tank and 'a' for 'attack' is easy to remember, very few games are so logical. For example, in Age of Empires, 'h' means 'select your Town Center' and 'c' means 'build a villager' ! 1b) Often the position of the hot-key on the keyboard is hard to reach. A right-handed person will use their right hand for the mouse and left hand for the keyboard - so q w a s z x are easy to reach, whilst o p k l n m are not. 1c) Often the order of the common key sequences is illogical. Most (western world) players 'think' in a left to right (and top to bottom) 'order' .. and 't' before 'a' means moving your hand 'backwards' across the keyboard - so in a hurry, instead of 'ta' many players will hit 'at' .. 2) In many games, you will want to issue a common sequence of commands as fast as possible, using one hand, whilst moving the mouse with the other. Having to hit a sequence of keys in an illogical order scattered all over the keyboard is very difficult to get right. For example, again in Age of Empires, as the games starts the hot-key user will type h c c c c . a q (select Town Center, build 4 villagers, select first free villager, build house) whilst the mouse user is still waiting for the graphics to be drawn on screen ! 3) Finally, for 'casual' game player, the need to actually remember all those obscure hot-keys combinations is a real pain. However there is a solution = plug-in a programmable hot-key macro keypad ! An 18 key USB numeric keypad can be had for then £10 from Amazon (or about 1/3rd that from China via eBay). This is used with a 'macro-keyboard driver' (such as the MS IntelliType driver or a 3rd the party driver such as HidMacros). The driver allows individual buttons on the keypad to be programmed with any hot-key sequence you want - which is fine if you can install the required Driver on your PC (and if the game uses the driver correctly). However it's not always possible to install a custom driver (or have the game recognise it). However, for the ultimate 'hot-key' assistant, you need something that will 'correct' your errors = for example, spot 'at' and send 'ta' to the game.

[top]

Enter the Pi Zero Keyboard Device

The Pi Zero can be set to bootup as a 'USB Keyboard Device'. All you then have to do is find a means of connecting the key buttons to the Pi and (of course) program the Pi to generate the required hot-key sequences. Once this is set-up, the Pi can be plugged into any USB port of any PC and it will be recognised as a 'standard keyboard'. Since the macro-key sequences are generated within the Pi, as far as the PC is concerned you are using a standard keyboard !

By using 'mode' switches (or using different button sequences), the actual number of different key buttons required can be drastically reduced from a full sized 'QWERTY' keyboard (where half the buttons can't be reached anyway).
 
It would even be possible to build (or re-use) something like the specilist gamers multi-button mouse (which typically cost from £50 up) where buttons are positioned directly under each finger and thumb for maximium speed.
 
The Pi can 'monitor' your key use - for example, you can reduce 10 number keys to a single 'next number' key - and this can even be setup so that the 'next number' key only cycles over the currently 'active' numbers.
 
Finally, the Pi can be programmed to avoid or 'correct' typical errors (such as getting the 'select, attack' key order wrong)
 
Having a 'clever keypad' whihc can be programmed to do almost anything will give you a massive advamtage over the players !

[top]

A DIY keypad

Since the Pi Zero's only USB port is unavailable (it's been reprogrammed to 'USB Slave' mode, so the Pi can be plugged into the PC as a 'Keyboard Device') you need some other way to 'sense' the keys.

Pi Zero W users can use a BlueTooth keypad, however that's going to be more expensive

If you only need half-a-dozen keys, you can wire these up to the Pi i/o lines and write some code to 'sense' which (or which combination) is pressed.

The button user should arrange 4 buttons on the top of the unit (so one lies under each finger) and up to 3 buttoms / switches on the side - where these lie under your thumb.
 
The thunmb button is typically used as a 'shift', so you have 4 finger buttons plus up to 3 shift+finger combinations, giving you a potential of 4 + 3x4 = 16 unique hot-keys, which should be more than enough to remember in the heat of battle.
 
Adding a (rotary) switch to the top of the control unit allows a 'mode' change (from 'movementt' to 'combat' to 'economy' to 'new unit build' say)
 
Adding some LED's will show, at a glance, what the Pi thinks you are doing ...
 
On it's 40pin header, the Pi has 24 usable i/o pins available, which should be more than enough (it actually has 26, however 2 of these are the Serial Command TxD/RxD lines which are best left alone since they provide a decent 'debug' path when problems are encountered)

[top]

Where to get the key buttons ?

Most of us will have old keyboards hiding in the loft. The very first keyboards - such as the Atari etc. - used high profile, 'chunky' key assemblies which contain 'reed' switches and magnets. These are extreamly reliable and individual key assemblies should be easy to desolder and reuse. Then came the Sinclair ZX81 and Spectrum style of flat keyboard. These had a 'bubble' membrains with a conductive underside that pressed down onto bare circuit board tracks. These were very unreliable and wore out quickly as users applied more and more force to complete the circuit. Manufactired as a single unit, it's virtually impossible to reuse them. Modern keyboards have individual keys fitted with spongy conductive pads pressing down onto gold-plated contacts within the base of the semi-sealed switch assembly. These are much more reliable, and it should be possible to desolder and reuse individual keys. Cheaper versions of the modern 'low profile' keyboard have a circuit board with bare tracks onto which the conductive 'pad' on the end of the key presses. These are a lot harder to chop up and reuse (as well as being harder to 'sense') As seems to be usual these days, it is typically much cheaper to purchase a ready-made key-pad (and dismantle it for the parts you need) than to purchase the individual components on their own. If you must buy components, and can plan 2-3 months in advance, the cheapest source is from China via eBay. If you don't have the time, there are plenty of UK sellers on Amazon who have purchased job lots from China via eBay and are reselling at the usual 100% mark-up. Somewhat more expensive are the UK mail-order companies, such as CPC and RS Components (CPC has a 'Bargain Corner' where you can sometimes find reasonably priced components). Finally there are the 'top of the tree' Raspberry Pi distributors. These are specialist sellers of 'maker' components to the doting parents of schoolchildren who are happy to pay prices that were only ever exceeded by the 'uber cost' UK High Street stores (such as the now defunct Maplin and long-gone Tandy) Your local Charity Shop can be a good source of old/ancient keyboards and keypads, where you can sometimes find things like 'door entry code units' for a few £'s (which is less than the cost of one key-switch, without key-cap, from CPC etc).

[top]

Off-the-shelf (serial) keypads

However the 'easy' way is to use the Pi Zero 'Command Console' serial link. A Serial Keypad can be found for less than £4 on eBay (for example, the 'LC Technology TTP229 16 Channel Touch Sensor Module').

Of course the real DIY anthusuast will want to dismantly and use parts of an old PS/2 style keyboard - say one that comes with numeric keypad buttons

  PS/2 Keyboard output is 'sort of serial' but you would need a 'converter' (eg PIC - the data rate is only 10-16 kbits per second so a simple code loop can be used to detect the Clk and sample the data = see my PIC Project pages) between the PS2 socket and the Pi Serial Command pins.   For more on how the PS/2 keyboard communicates with the PC, see this PS/2 Keyboard specification (PDF)

[top]

Hot-key sequences

A USB Keypad plus simple keypad macro driver (mentioined above) lets you program each key to deliver a set sequence of hot-keys - and this may be all you need. A key-pad with a 'NumLock' key function even allows the software driver to switch 11 of the keys (the 0-9 and '.' keys) betwween two 'modes'

However, a Pi Zero + serial keypad approach not only allows mutiple different 'modes' but also allows you to program 'context sensitive' hot-key sequences (i.e. where the hot-key sequence transmitted depends on the order in which the keys are presssed)
 
For example, in Age of Empires, you might want to mode switch between 'battle mode' and 'build' (ecomomy) mode = in which case it's a good idea to fit a LED to show which mode you are in == so the 'NumLock' key is the obvious one to use !
 
Whilst preparing for battle, you would typically assign parts of your army to one of the 10 'contol groups'. To fight, you would select one of the control groups and then the mouse clcik the enemy you wanted then to 'target'. In a melle, troops become inter-mixed and it's impossibe to use the mouse to 'area grab' only a single type, so extra clicks are needed to restrict the selection to one type before you give them orders. The hot-key group user thus has a real speed advantage.
 
However switching groupd during fighting means moving from one group to the next .. and that means moving your hand from one keypad key to the next.
 
In a 'context sensitive' system, one key would be assigned as 'next group' - the first click would select group 1, the next group 2 and so on. After each key press, you use the mouse to designate a 'target' (for that group).
 
The clever bit is that you use the keypad to set up the groups - so the Pi can monitor how many groups you have setup. During battle as you just keep hitting the same key the Pi can 'cycles round'. By the time you get back to group 1 (and set it a new target) the enemy will still be trying to remember which troops are in which group (and then find the button on his keyboard) or be busy trying to restrict area selection to just one troop type.

In many games there is a 'sart up' sequence you have to go through - and in the RTS, players who are 'fast off the mark' will get the advantage. The problem is that whilst focussing on strat up, the fast players attention is not on the game display - and in 'random map' games that means he soon has to stop and check the display

In Age of Empires, at the start of the game, the typical player selects his Town Center, builds 4 villagers, switches to the 3 start villagers, selects one to build 1 house, sets the other 2 to build a second.
 
Next they send their Scout off to find the resources that you will need to build your economy (and later to find the enemy). Sending the Scout on a 'spiral' run to around your Town Center is a time-consuming task involving the setting of 'way points'.
 
Finally, they need to set the 'gather point' for new units - so the Town Center is selected again and the gather point set.
 
Most of the above can be sent as a hot-key sequence (placing the 2 houses requires a visual check that the ground is clear before placing the house using a mouse click).
 
However it would be quite possible to 'program in' the Scout 'spiral' search as a series of hot-keys = 'select idle military unit', followed by a series of scroll righ/down/left/up keys.

Note that a standard Numeric Keypad has 18 buttons = the '0' and 'Enter' keys are double sized (a 19 button keypad splits the double sized 0 into two standard sized keys, '0' and '00' (or '000')). It's a 'good idea' to use the (easy to find) double sized keys for 'most' actions.

For example, one key can be defined as the 'start game' key (in Age of Empires, the Pi would then send 'hccc.aq' to the PC). After the 'start' key is pressed, the Pi can then assist with the setting up and use of 'Control Groups' In AoE, there are 10 Control Groups. To set up a Group, you use the mouse to select a number of units, then hold the Ctrl key down whilst hitting one of the number (0-9) keys. The 'average' user will find it almost impossible to hold down ctrl with one finger of their left hand whilst hitting a number key with another finger of the same hand, although ctrl+1 to ctrl+6 are just about possible if you use your thumb to hold ctrl. To select a Group, you hit it's number key - and again, 1 to 6 are perhaps reachable in a hurry with the left hand, however 7 to 0 mean travelling right across the keyboard. To center the group in the game window, you hit the same number twice in quick succession. It is possible to add units to a group (first you select the Group by hitting n (it's number key), then, whilst lding Shift, you left-clcik the additional units., then you 'update' the Group with Ctrl+n) One problem with Groups is the need to remember how many Groups you have setup - if you get this wrong and Ctrl+n over-write an existing Group you could loose a battle when the expected Group can't be found. If you forget which units are in which number group it's not (usually) fatal, just a pain to hit the keys 1 2 3 4 5 6 7 8 9 0 all along the top of the keyboard. The Pi allows a much easier - and thus faster - approach. For example, you could define two buttons = 'setup (next free) Group' and 'select (next) Group'. To set up a Group, use the mouse to highlight the units, and then either :- hit 'setupG' and 'n' (some specific number, 0-9), in which case the Pi sends 'ctrl+n' to the PC. or :- hit 'setupG' and 'nextG', in which case the Pi assigns the next available free 'n' group when it sends 'ctrl+n' to the PC. This avoids the need to hod down the Ctrl key whilst hitting a number and avoids the need to remember which next 'n' is free. To select a group, the player can hit it's number on the keypad, or just keep hitting 'nextG' as many times as necessary untill the required Group is found. Needless to say, in both uses the 'next Group' number 'n' will 'wrap around'. Since the Pi will be clever enough not to attempt to select a group n that has not been defined, if you set-up (say) 3 Groups, using nextG 4 times will cycle around all 3 groups and back to the first. In combat, the ability to auto-cycle round can give the hot key user an overwhelming advantage. For example, say both sides have 18 archers and it takes, on average, 5 hits to kill an archer. So you setup 3 groups of 6 archers each (so each group can kill one enemy archer 'per shot'). Your archers will be 'spread out' = if the enemy leaves it to the AI to select targets, it will typicaly keep shooting at one target until after it is dead. If you bunch up, the AI will spread it's shots amongst your archers - you want it to over-kill one archer at a time so it wastes arrows, not gradually kill your entire force (if you have Minks healing your archers, 'gradual kill' is exactly what you want, but for now I'm assuming no monks). The problem with letting the AI choose targets is it's 'keep shooting until it's dead' approach. Since you will both open fire at max. range, the arrows of your first shot will usually still be in the air when you fire your second. This means the target is still alive when the second shot is fired, even if it's about to die from the arrows of the first shot. A human player, knowing this, will switch target for the second shot - the AI won't (and ends up double kiling the target). A 'mouse menu' player will use his mouse to select all his archers and right click one of your archers each go as a new target. In almost the exact same time, youur 3 groups can aim at 3 seperate targets (hit nextG, right click an enemy archer, hit nextG, right click another, hit nextG and right click a 3rd). With the arrows of the first shot still in the air, both sides will now select new targets for their archers secoond shot. As they fire the second shot, one of your archers will be hit 18 times and die, whilst he will loose 3 of his archers, each having been hit 6 times. With the second shot arrows in the air, both sides select targets for their 3rd shot. At this stage, he will be down to 15, whilst you will have 17 (2 Groups of 6, one of 5). When the 2nd shot lands, you will loose a second archer, whilst he looses 3 more. He now has 12, you 16 - worst case that's 2 Groups of 6, one of 4 (which means one of your groups can't kill in a singe shot). On the 3rd shot, you loose a 3rd, he looses 2 plus one 'half dead'. He has 10.5 you 15 - worst case that's a 6, a 5 and a 4. On the 4th shot, you loose a 4th, you target 2 new enemy with your 6 and 5 Groups whilst 'skipping over' the group of 4 (which means they will automatically retarget the archer they left 'half dead' by their previous shot). He looses 3 and is now down to 8, you have 14 - again 'worse case' that's a 6 and 2x 4's. By now most enemy players will see the 'writing on the wall' and withdraw. However if the battle continues :- On the 5th shot you will lose one more, he will loose one plus two 'half dead'. He is down to 7 and two half dead, you have 13, one Group of 5 and two of 4. The final shot is decisive - you target one new enemy (with your 5 group) and skip both groups of 4 (which retarget the two half dead enemy). You will loose another archer and be reduced to 12, whilst he looses 3 and is down to 4 archers, which is not enough to kill one of yours with his next shot. With the time saved by skipping 2 groups, you can now afford to take a 'time out' to re-arrange your 12 archers into two groups of 6. To be fair, let's assume you are a bit slow and the enemy is quick enough to get off a 'free shot' with his final 4 archers, which will 'half kill' one of yours. On the following shot, we can assume he will finish off your half dead archer, however your 6 and 5.5 will kill 2 of his. You will be down to 11 (a 6 and a 5) whilst he is down to 2. When the final shot lands his last 2 archerss will 'part kill' one of yours, whilst both of his die. Worse case, you end the battle with 11 archers (of which one is wounded), having lost 7. He will have lost all 18. Best case, he is unaware of how many hits are needed to kill and spreads his fire more evenly over your groups. Starting with 3 groups of 6, he reduces each to 5 in the first 3 shots (and looses 9 archers, so down to 9). On the 4th shot, he looses 3 more archers (6) but reduces one of your Groups to 4. On the 5th, he looses 2.5 (3.5) and can now only wound. So, best case you end with 18-5 = 13 archers of which one or two are wounded.

The pages in this topic are :-

  + Age of Empires hot keys == Latest changes (modified 29th May 2018 14:31.)


Next page :- Age of Empires hot keys

[top]