BBC BASIC for Windows
Programming >> BBC BASIC language >> Shortcuts http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1279133957 Shortcuts
Post by JB91 on Jul 14th, 2010, 6:59pm
How do you put in your program keyboard shortcuts like CTRL Z and CTRL O?
Re: Shortcuts
Post by admin on Jul 14th, 2010, 7:19pm
How do you put in your program keyboard shortcuts like CTRL Z and CTRL O?
They can be read using GET, GET$, INKEY or INKEY$ just like any other characters from the keyboard. CTRL-Z is ASCII code 26 (SUB), CTRL+O is ASCII code 15 (SI). The full table of ASCII codes can be found in the main Help documentation here:
The supplied example program GUIDEMO.BBC responds to both menu selections and keyboard shortcuts .
Richard.
Re: Shortcuts
Post by JB91 on Jul 15th, 2010, 3:13pm
I tested it out and it seemed fine, but when I put it in my text editing program, it doesn't do anything. Any sugegstions?
Re: Shortcuts
Post by admin on Jul 15th, 2010, 5:18pm
I tested it out and it seemed fine, but when I put it in my text editing program, it doesn't do anything. Any sugegstions?
The reason nothing happens is that the Windows Edit Control, which your program uses, takes the input focus away from your program. Therefore any input from the keyboard goes to the edit control rather than to your code.
There is no simple solution to this. The 'official' way would be to subclass the edit control and intercept the keyboard input, but this is an 'expert level' technique! You could try using the SUBCLASS library, which might at least allow you to write the code in BASIC, but failing that it would need assembler code.
You might be able to devise a satisfactory workaround by using INKEY with a negative parameter to test the keyboard directly, but it's quite difficult to guarantee that you would always see the shortcuts even if the keys were held pressed only for a short time.
So unfortunately I can't offer you a solution which is both straightforward and reliable! If it's any consolation (probably not) this is a tricky problem in any programming language, not just in BBC BASIC, because it's not something Microsoft seems to have made specific provision for.
Richard. Re: Shortcuts
Post by admin on Jul 16th, 2010, 10:38am
OK, I found a workaround for your issue. The trick is to use a Keyboard Accelerator to convert the keyboard shortcuts to menu commands. The only awkward part is that to make this work you need to put the Edit Control in a dialogue box.
I have uploaded a modified version of TEXTEDIT.BBC here:
Am I supposed to just copy and paste it from the TEXTEDIT program? Because it doesn't work if you do it.
Obviously you may have to adapt it somewhat to the requirements of your program. I've given an example of how to do it, but it's up to you to work out exactly how to apply that example to your program. I can't write your code for you!
Richard. Re: Shortcuts
Post by JB91 on Jul 18th, 2010, 11:26am
I did it, but whenever I typed, it comes up with:
"(C) Copyright R.T. Russell 2009"
Josh.
Re: Shortcuts
Post by admin on Jul 18th, 2010, 4:41pm
I did it, but whenever I typed, it comes up with: "(C) Copyright R.T. Russel 2009"
Firstly, your copy of BBC BASIC for Windows is out of date. Only the current version is supported, which is 5.91b; update your copy (it's free) and see if that makes a difference.
Secondly, the name is Russell with two Ls, not Russel.
Thirdly, what you are seeing is the 'default' error message, i.e. what REPORT$ contains when no error has occurred. You need to debug your code to find out why. See here for hints on debugging: