Detecting Alt + cursor keys
Matthew Phillips (473) 687 posts |
If you hold down Alt and press any of the cursor keys you do not get a Wimp key pressed event. We’d like to use these key combinations in a Wimp application. What is the best way to detect the user pressing Alt and a cursor key? Are Alt + cursor keys supposed to be reserved for some specific purpose? |
Steve Pampling (1551) 7932 posts |
If you run !StrongKey from here it reveals the key codes obtained (Low level, Wimp, KeyEvent)
Victims of the Alt key combinations used to produce accented characters etc perhaps? 1 In my case it’s a means of producing a keyboard mouse built into the Filer so Ctrl-arrow is OK. As long as I’m not fighting StrongED or similar for use of the key combination :) |
Clive Semmens (2335) 3130 posts |
In days of old when IKHG was bold and Acorn’s own keyboards existed (that is, at least up to and including RISCPCs) rather than PS2 or USB ones you could write a keyboard driver that could give you whatever you wanted in the buffer in response to any combination of Shift/Alt/Ctrl+otherkey. I know because I wrote several, and Acorn User published my article about them and their uses. I miss IKHG (International Keyboard Handler Generator). There used to be a similar (albeit far less friendly) facility on Windoze machines, at least up to PS2 keyboards. I was offered a contract to write one for this lunatic keyboard: http://clive.semmens.org.uk/024_ROUGOL/10s_MadKB.jpg by a Microsoft Fellow who’d seen my Acorn User article (A Microsoft Fellow reading Acorn User?? Or perhaps someone else drawing his attention to it, I don’t know.) My son did the contract, a nice little earner for a fourteen year old. I don’t think the keyboard ever went into production. |
Steve Pampling (1551) 7932 posts |
There’s a few bits of software around that rely on patches to that area to be able to use Alt-key combinations. I presume IKHG is languishing in some 26bit storage somewhere. |
Clive Semmens (2335) 3130 posts |
Perhaps, but I don’t know how easy it would be. The 26-bit to 32-bitting shouldn’t be too hard, but I don’t know enough about the differences between Acorn keyboards, PS2 keyboards, and USB keyboards and the way they communicate to know whether that’s going to be a large additional barrier. |
Dave Higton (1515) 3404 posts |
I don’t think the transport mechanism is that important. What matters is the data that are transported, which I believe are the same for USB and PS/2, so it may be easier than you think. |
Clive Semmens (2335) 3130 posts |
As long as the interpretation of what key combinations mean is done by the computer, not in the keyboard, yes. If it’s done in the keyboard, it’s still okay if how the keyboard interprets things is programmable with communications from computer to keyboard, and sufficiently flexible. If such programming works the same for PS/2 and USB that’s good. For all I know it’s entirely done at the computer end, which is obviously best of all. I would be delighted if someone could dust of IKHG! Sadly that someone certainly isn’t me. |
Dave Higton (1515) 3404 posts |
The keyboard sends nothing more than key presses and releases. |
Jon Abbott (1421) 2601 posts |
You’ll need a Module that has its own Wimp handle, that claims EventV Watch for Event 11 but don’t claim them. You’ll need to enable Event 11 via OS_Byte 14 once you claim EventV and disable via OS_Byte 15 when you release. It’s just a case of tracking the Left/Right Alt and cursor “key down” states via their internal key codes Once you’ve detected what you’re looking, send a Wimp message to your app via Wimp_SendMessage I don’t know if there is a best way as such, as some keyboards don’t necessarily return the correct codes. For the pi-top for example, I had to write a USB driver to get all the keys working correctly. I think you’ll be okay with Left Alt, Right Alt however can sometimes be handled by the keyboard itself, so may not return the correct code when used in combination with other keys. |
Rick Murray (539) 13406 posts |
Keyboard just sends standardised key codes. It’s RISC OS that translates codes into characters. Useful because I can make a French keyboard British by sticking new labels on and telling RISC OS that it’s UK layout. ;-) Which part of the OS actually does the translation? At a very brief look, the keyboard handling looks… Convoluted.
I did that. It’s basically how MoreKeys worked. I got firmly told off by nemo who said “write a keyboard handler” (which is a ridiculous pile of nonsense for trapping some specific key combinations). It seems to me that, like Territory, we’re running into the limitations of hardcoded things that don’t make sense being hardcoded in the year 20xx… Oh, and I gave up on using Alt combinations in REdit because InternationalKeyboard hijacks them at a lower level that you can get to to make its replacements, and, like detecting PageUp vs ShiftUp, all methods and workarounds are tedious and ridiculous. |
Steve Pampling (1551) 7932 posts |
Talking to myself here, but the phrase “well that’s a bit annoying” (or equivalent) will get a fair bit of exercise for a while.
1I will figure it out, I’m not going to drop it. Not my habit, ever, pre-school and onward. |
Rick Murray (539) 13406 posts |
I believe the usual “hack” is to open a window offscreen that gets notified of keypresses. Edit has “hotkeys” and Switcher has “grabkeys”. Switcher opens the window with R1 and R2 (min X, min Y) set to “-bignum”. |
Steve Pampling (1551) 7932 posts |
I believe the usual “hack” is to open a window offscreen that gets notified of keypresses. Ah, official cheats. I suppose a hot key to push focus to that window would be “form” to steal attention away from keypress hogs like say Zap/StrongED |