Ctrl + alpha Character Codes
Pages: 1 2
Andy S (2979) 504 posts |
Gah yet again after scouring the documentation I feel sure I am missing (or have forgotten) something obvious! :-( When you intercept Wimp Key_Pressed events, how do you calculate character codes for the alphanumeric keys when Control is held down? Where is this documented? https://www.riscosopen.org/wiki/documentation/show/Character%20Codes doesn’t mention the alphanumeric keys. Is this something that’s missing from the PRMs? I guessed that the codes might be based on the ASCII codes of the characters but I don’t understand how Control or Shift modify them. Looking at the code of Draw, for letters with Control it seems to be: [ASCII Code of Capital Letter] - 64 so Ctrl-A is 1, Ctrl-B is 2, etc. but where is this documented? I’m happy to add a short paragraph to the Character Codes page if it isn’t, provided someone can confirm the behaviour to me. |
Rick Murray (539) 13404 posts |
Yes, I believe this to be correct. Try the section on character input, because it seems to me to be a thing inherited from the BBC MOS (Ctrl-something to enable paged mode, Ctrl-something else to spool to printer…). |
Jeff Doggett (257) 231 posts |
It’s industry standard, so pretty much everywhere! |
Andy S (2979) 504 posts |
It’s industry standard, so pretty much everywhere! Ah yes, of course. I remembered that Ctrl-G played the bell (beep) character and now it makes sense that Ctrl-G is 71-64=7. I suppose the Ctrl key is so named for the ASCII Control characters. I knew most of this already but I’ve not pieced the information together this explicitly before. Thank you. What about Shift though? In normal ASCII shift would just capitalize a letter, so what happens to the character code under RISC OS? I can try it myself sometime for the answer, but not today – I’m shattered! This: http://sta.c64.org/cbm64petkey.html suggests Shift-A may produce code 193 but that doesn’t sound like part of the ASCII standard to me. |
Jeffrey Lee (213) 6046 posts |
For regular printable characters, the behaviour will be determined by the keyboard layout, and your app will be supplied the shifted key directly. For non-printable characters, I’m not sure exactly what the logic is. Presumably that character codes wiki page covers all the main cases, but maybe there’s some extra rules for things like Ctrl-Shift-A.
Correct, PETSCII != ASCII. The clue is in the name ;-) |
Andy S (2979) 504 posts |
Thanks Jeffrey. For some reason last night I was convinced that hitting the ‘A’ key without Shift or Caps Lock would still produce 65 instead of 97 (as in, the Key_Pressed event relating more closely to the physical key than the intended ASCII character). Correct, PETSCII != ASCII. The clue is in the name ;-) Yeah, it would be obvious, if not for code induced sleep deprivation. ;-D |
Andy S (2979) 504 posts |
I’m reviving this thread, now I’m working on keyboard shortcuts again, just in case anyone finds it, looking for the answers. Presumably that character codes wiki page covers all the main cases, but maybe there’s some extra rules for things like Ctrl-Shift-A Ctrl-Shift-A produces the same code as Ctrl-A, 1, but you can just check the state of the shift key separately using OSBYTE &81 (although this might be unreliable if the Shift key is released before the other two keys, for example). This was tested using RISC_OSLib. |
Steve Pampling (1551) 7932 posts |
Along the lines of these?
Many are relatively easy by reusing code elsewhere in the module, or in the case of Rename simply filling in the message to reveal what ROOL already did. I must admit to being a little distracted by my attempts to get mouse button action accompanying the mouse move with arrows without having to add code to duplicate something that already exists (if you dig enough) Edit Note that without the use of Fred Grautes wonderful Transient/TrapDelete, forming a very nice Recycle bin with automated scheduled full delete, the single key Delete option on Del could be a bit painful. |
Andy S (2979) 504 posts |
Yes they’re easy to implement but some are a pain to test in RPCEmu because they don’t reach it, getting intercepted by the host OS. |
Steve Pampling (1551) 7932 posts |
Yup, plain Winlogo throws up the Windows action obscuring your test, but I’m not sure whether that’s my fault for allowing it to escpe unconsumed or whether it escapes anyway. Logo+shift and logo+ctrl aren’t touched. !StrongKey is excellent for testing which are available BTW. My choice of keys is based on a combination of info from QuickFiler, RO6 and Windows and trying to be logical – hence the intent of sh-F1 for info after F1 has the logical use of Help. What would be really nice is if the Alt-key combinations were available. I appreciate that they have a historic use, but a simple config option to go legacy or new-shortcuts would be nice, particularly for alt-arrow navigation without clashing with regular use in text editors for ctrl-arrow. |
Andy S (2979) 504 posts |
What would be really nice is if the Alt-key combinations were available. Agreed. I was hoping to use Ctrl with alphabetic letters for most of Paint’s transformations and then modify it with Shift (or Alt if that had been available) for a reverse transformation (e.g. Ctrl+F for Flip vertically, Ctrl+Shift+F for Flip horizontally) but the WIMP’s support for these combinations isn’t good (you seem to get multiple events that would then need some kind of debouncing logic). I thought about e.g, Ctrl+X for Scale x, Ctrl+Y for Scale y but thought better of it as we may add clipboard support in future. I’m probably going to go with using all the function keys (except F12 of course) instead. |
Steve Pampling (1551) 7932 posts |
That could be ctrl-R for Reflect and a matching ctrl-sh-R As far as clipboard is concerned the logical ones to avoid would be the typical cut/copy/paste stuff as used on other GUI OS implementations. Anything else is probably fair game in the context world – e.g. my ctrl-arrow movement implementation hacked into Filer
The latter means that a means of grabbing the focus with a single key is required to pull the focus to Filer and the former means you have to do a little “official cheat” like switcher etc and open a window that never closes at a non-visible location as Rick pointed out. If you’re in another app that uses ctrl-P that wouldn’t work but if we allow Escape to pull focus to Filer, which doesn’t use ctrl-P then Escape, ctrl-P moves you into Paint.
Had you thought about ctrl-right-arrow for increasing x-scale, ctrl-left-arrow to decrease?, similarly up arrow and down arrow for y scale. |
Andy S (2979) 504 posts |
That could be ctrl-R for Reflect and a matching ctrl-sh-R Well, R was going to be for rotate but you’re missing the point which is that the WIMP doesn’t seem to have built in support for Ctrl+Shift+<Alphabetic letter> (presumably why that combination doesn’t appear in Draw, Edit, Filer, etc.). If you type Ctrl+Shift+R it generates the code for Ctrl+R and if Shift isn’t released or pressed at exactly the correct moment (or perhaps even if it is!) then the key event is received multiple times! At least, that’s what I’m seeing in Paint’s log when I try this with RISCOS_Lib. |
Andy S (2979) 504 posts |
As he noted Edit does the same and I presume Paint does too so perhaps something like ctrl-P could be used to pull (push?) the focus to Paint and thereafter you get first dibs on the key shortcuts. At the moment my current build of Paint takes the input focus when you click Select or Adjust in the sprite window (which normally also starts painting [but some people want two clicks for this – refer to the bounty task and discussion – I’ll probably make it configurable]). A special keyboard shortcut like Ctrl+P just to send the focus to Paint sounds a bit nasty, IMHO. It might be better to implement an equivalent of Windows and other OS’s Alt+Tab to cycle the focus across open windows. |
Steve Pampling (1551) 7932 posts |
An alternate, logical interpretation for R
There are arbitrary limits on the number of keypress values and some strange ‘omissions’. Unless I’m misremembering the normal pattern in the Filer and Wimp is to take a key (or mouse button) event and unless the state is held for longer than the delay interval (see keyboard or mouse configure) is exceeded the press/release is treated as one event not many. That said I’ve noticed some quirks in RPCEmu on that front. I think a comment Rick made sums it up keyboard handling is weird.
Probably, assuming you mean applications with/without open windows. I seem to recall a few bits of software from the 26bit era that did that kind of trick. |
Andy S (2979) 504 posts |
Yes it’s possible RPCEmu is causing strange behaviour with Ctrl+Shift+Letters. That alone though is a point against using those combinations, I think, combined with the fact that Acorn’s applications don’t seem to use them and they’re not documented in the PRMs. |
Fred Graute (114) 627 posts |
You might want to have a look at DeepKeys which provides much better support for keyboard shortcuts. Especially when used in conjunction with my StrongKeys module. Not sure though if the use of DeepKeys is appropriate for an ‘official’ application. |
Fred Graute (114) 627 posts |
Might it be CoolSwitch (26-bit only) that you’re thinking off? I believe MiniDisc has a similar facility. |
Frank de Bruijn (160) 224 posts |
Not really: https://aconet.org/tools/#coolswitch |
Steve Pampling (1551) 7932 posts |
I’m not sure about the PRM content. I’ve always found it difficult to find a complete coherent set of info about keypress behaviour. 1 I’m sure everyone is familiar with those places that are so secure that even the person putting things there can’t find them never mind access them. |
Steve Pampling (1551) 7932 posts |
I’m pretty sure Nemo regards DeepKeys as something that only exists because of a deficiency in the OS and if someone fixed the OS it would be a much better situation. BTW. Anyone else noticed that his site shows DeepKeys 2.08 but that isn’t downloadable, if you dig behind the scenes 2.06 (2003 vintage) is available. I seem to recall him doing recent work for ARMv7 or something – not there anyway. |
Steve Pampling (1551) 7932 posts |
Possibly, but I’m reasonably sure there was more than one, and as Frank points out he 32bitted Coolswitch anyway. |
nemo (145) 2437 posts |
D’oh. Fixed. 2.08 is from 2004 so is MUCH more modern. Ahem.
Hmm. DeepKeys does two different things. Sadly RISC OS 4 broke one of them. • Buffers keyboard modifiers with the keypresses that they generate, and delivers them in an augmented Wimp KeyPress event RO4 changed the way the Wimp dealt with keypresses, and unlike earlier versions assumes that keypresses are always bytes. So “wide” keypress codes get mangled by the Wimp. Which is sad, but nobody was using extended key codes like I envisioned so it’s no great loss. However, the modifiers-in-KeyPress-event is very useful and many programs make use of that. There’s no problem with including DeepKeys if it’s useful, and a program that uses it can detect whether the extended keypress event is present, and can do the flawed work-around of reading the modifiers on message receipt if DeepKeys isn’t available. |
Steve Pampling (1551) 7932 posts |
I could have sworn you’d written of more recent work on DeepKeys. Clearly grey cell failure over here.
With access to source it’s possible to unbreak many things. (Assuming inclination and talent) |
Steve Pampling (1551) 7932 posts |
Anyone else noticed that his site shows DeepKeys 2.08 but that isn’t downloadable Sorta fixed. :)
Don’t sell yourself short. “(Note that prior to version 2.08, the Logo and Menu keys did not return a valid physical key number when pressed in isolation – they now do)” 1 Persistence, I think it’s genetic. |
Pages: 1 2