keyboard keys
-
- Posts: 5
- Joined: Sat 09 Mar 2024, 19:30
keyboard keys
How does one programme keyboard keys to move around the screen and select numbers and letters? The same question applies to using the mouse as a device to move and select.
-
- Posts: 200
- Joined: Tue 17 Apr 2018, 21:03
Re: keyboard keys
Hi Steve,
Can you be more specific, there are several depending on what you are doing with the result.
INKEY with a negative argument is probably the one to use for keys in a game.
And
MOUSE x,y,b for the mouse
Kind regards Ric
Can you be more specific, there are several depending on what you are doing with the result.
INKEY with a negative argument is probably the one to use for keys in a game.
And
MOUSE x,y,b for the mouse
Kind regards Ric
Kind Regards Ric.
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
-
- Posts: 5
- Joined: Sat 09 Mar 2024, 19:30
Re: keyboard keys
Thanks Ric,
I sent a reply a couple of days ago, but it seems to have got lost.
Here is another go.
I am trying to devise a board game along the lines of chess, draughts and similar. I have looked at the example programme of Sudoku and want to include in my programme, the user being asked to use the arrow keys to move across a grid and to press a key to select a letter or number. Using Inkey seems too cumbersome and I think using keyboard keys to input data direct would be ideal. I just can't see any keyword that enables the keyboard to be used as I have described. Any help from forum members would be much appreciated. Thanks.
Stevewilson
I sent a reply a couple of days ago, but it seems to have got lost.
Here is another go.
I am trying to devise a board game along the lines of chess, draughts and similar. I have looked at the example programme of Sudoku and want to include in my programme, the user being asked to use the arrow keys to move across a grid and to press a key to select a letter or number. Using Inkey seems too cumbersome and I think using keyboard keys to input data direct would be ideal. I just can't see any keyword that enables the keyboard to be used as I have described. Any help from forum members would be much appreciated. Thanks.
Stevewilson
Re: keyboard keys
Would GET (or GET$) give you what you need? They return the ASCII code (or the letter itself as a string character) when a key is pressed - you can then do what you want to with it.
Best wishes,
David
Best wishes,
David
-
- Posts: 5
- Joined: Sat 09 Mar 2024, 19:30
Re: using the mouse to move and select
Hi,
After many years away from using BBC Basic, I am struggling getting to use the mouse as an inputter of data instead of the keyboard.
I have used an example programme which utilises the mouse to move position and draw lines, but I cannot see how I get it to select a letter or user defined character, move it to another location, and then delete it from its original position. I have tried using a combination of GET$, INKEY$ and MOUSE x,y, b to no avail. Some pointers to what I should look at would be appreciated!
Steve W
After many years away from using BBC Basic, I am struggling getting to use the mouse as an inputter of data instead of the keyboard.
I have used an example programme which utilises the mouse to move position and draw lines, but I cannot see how I get it to select a letter or user defined character, move it to another location, and then delete it from its original position. I have tried using a combination of GET$, INKEY$ and MOUSE x,y, b to no avail. Some pointers to what I should look at would be appreciated!
Steve W
-
- Posts: 327
- Joined: Wed 04 Apr 2018, 06:36
Re: keyboard keys
VDU5is what you need as that enables you to write text to a graphics cursor. It also helps if you use a monospaced font.
Here is a very rough program that will select and move one letter, but once you get the idea, I'm sure that you can adapt and generalise for your needs.
Code: Select all
VDU5
OSCLI("FONT Ariel,48,B")
GCOL3,10
MOVE100,200
PRINT"KEN"
REPEAT
MOUSEx%,y%,b%
UNTILb%=4
IFx%>100ANDx%<180ANDy%>100ANDy%<180THEN
MOVE100,200
PRINT"K"
REPEAT
MOUSEx%,y%,b%
MOVEx%,y%
PRINT"K"
WAIT 1
MOVEx%,y%
PRINT"K"
UNTILb%=0
MOVEx%,y%
PRINT"K"
ENDIF
VDU4
- JeremyNicoll
- Posts: 72
- Joined: Sun 26 Jul 2020, 22:22
- Location: Edinburgh
Re: keyboard keys
Steve, as nobody reading your questions knows how you're drawing your grid - eg are you just using ASCII characers like "+" (line intersection), "-" part of a horizontal line, "|" part of a vertical line ... or the top-bit-set ASciI chars similarly, or PLOTting lines in a graphics window .... or something else ... it's hard to make sensible suggestions.
Regarding "moving" a character ... are these characters just (say) letters or digits, or are they icons (eg tiny avatars of game players)?
To delete a character from some place, you might be able (if eg it was drawn in one colour on a different-coloured background) to draw it again using the backround colour. Eg if your char was drawn in blue on a black background, redrawing it in black would 'hide' it. But if your character was drawn over parts of a grid, or overlapping other characters, then that wouldn't restore the underlying grid or other characters.
One way to remove a character from a display is to save the look of the area of the display that the char is going to be drawn over before you draw it. Then to get rid of the character you replace that section with what used to be there. [I did that in a BBC micro graphics program I wrote in the mid-1980s where the character concerned was plotted onto a screen whose contents were completely arbitrary. I knew how many pixels high & wide the character was, depending on what direction it was pointing in, & where I was about to plot it on the screen ... so made a copy of the bytes in the screen memory of the area of the screen it would be plotted to, then drew it. Later if it had to be moved, I restored those bytes.]
Another way, if your display was drawn (from the start) by drawing the grid, then positioning a series of characters on it, one by one, with some overlapping others, is to clear the screen & redraw everything up to but not including the character you no longer want. On modern, very fast machines, where a whole complicated screen can be drawn in a tiny fraction of a second, that's possible.
Regarding selecting somethihg with the mouse ... again how you might do so depends on how you drew things - OS support for clicking on an icon in a window to select it probably doesn't work for things that are not icons... But you must know where the mouse is pointing & should be able to determine if it is pointing close to the centre of one of your characters. If you are continually monitoring its position you might be able to change the appearance of the mouse pointer to show it's detected something, or you might - if the user right-clicks at that point be able to indicate that it's selected your character. If you're not monitoring then you could use a right-click anywhere on screen to test - at that instant - if the pointer is near something significant.
I think that to get better advice you'd need to share your code so people can see how you've done things. Even some screenshots of the grid & characters on it would make it easier for people to visualise what you mean.
Regarding "moving" a character ... are these characters just (say) letters or digits, or are they icons (eg tiny avatars of game players)?
To delete a character from some place, you might be able (if eg it was drawn in one colour on a different-coloured background) to draw it again using the backround colour. Eg if your char was drawn in blue on a black background, redrawing it in black would 'hide' it. But if your character was drawn over parts of a grid, or overlapping other characters, then that wouldn't restore the underlying grid or other characters.
One way to remove a character from a display is to save the look of the area of the display that the char is going to be drawn over before you draw it. Then to get rid of the character you replace that section with what used to be there. [I did that in a BBC micro graphics program I wrote in the mid-1980s where the character concerned was plotted onto a screen whose contents were completely arbitrary. I knew how many pixels high & wide the character was, depending on what direction it was pointing in, & where I was about to plot it on the screen ... so made a copy of the bytes in the screen memory of the area of the screen it would be plotted to, then drew it. Later if it had to be moved, I restored those bytes.]
Another way, if your display was drawn (from the start) by drawing the grid, then positioning a series of characters on it, one by one, with some overlapping others, is to clear the screen & redraw everything up to but not including the character you no longer want. On modern, very fast machines, where a whole complicated screen can be drawn in a tiny fraction of a second, that's possible.
Regarding selecting somethihg with the mouse ... again how you might do so depends on how you drew things - OS support for clicking on an icon in a window to select it probably doesn't work for things that are not icons... But you must know where the mouse is pointing & should be able to determine if it is pointing close to the centre of one of your characters. If you are continually monitoring its position you might be able to change the appearance of the mouse pointer to show it's detected something, or you might - if the user right-clicks at that point be able to indicate that it's selected your character. If you're not monitoring then you could use a right-click anywhere on screen to test - at that instant - if the pointer is near something significant.
I think that to get better advice you'd need to share your code so people can see how you've done things. Even some screenshots of the grid & characters on it would make it easier for people to visualise what you mean.
-
- Posts: 5
- Joined: Sat 09 Mar 2024, 19:30
Re: keyboard keys
hi Ken and Jeremy,
Thanks for your replies. I am absorbing what you both have said, and I will see what I can understand! I will post a reply to let you know how I got on.
Steve W
Thanks for your replies. I am absorbing what you both have said, and I will see what I can understand! I will post a reply to let you know how I got on.
Steve W
- JeremyNicoll
- Posts: 72
- Joined: Sun 26 Jul 2020, 22:22
- Location: Edinburgh
Re: keyboard keys
I forgot to say that the "redraw" everything every time approach is demonstrated in the EXAMPLES\GRAPHICS\ALIENS.BBC sample program. Here it runs at 53 frames per second.
-
- Posts: 41
- Joined: Sat 28 May 2022, 22:40
Re: keyboard keys
The traditional method is to record the 'cursor' coordinates in variables.stevewilson wrote: ↑Sat 09 Mar 2024, 20:36 How does one programme keyboard keys to move around the screen and select numbers and letters? The same question applies to using the mouse as a device to move and select.
Call an input routine to modify the coordinate variables.
Call an output routine to redraw the cursor.
Other than the INPUT statement which accepts keyboard characters (and displays them as typed) until the buffer is filled, then passes that buffer to the input variable when RETURN is pressed, you have the following functions:
GET and GET$ - waits for a keypress (or accepts the next one from the buffer) and returns the ASCII or string value.
INKEY and INKEY$ - doesn't wait (unless a time parameter is specified) and returns the ASCII or string value of the keypress at the time the function is encountered.
The above accept <shift> and <control> modifiers so values for lowercase, uppercase and control codes are distinct.
Also there is INKEY(-n) where n is a value causing the function to only check for a specific keypress at execution time.
So you check the table to identify which value is needed to test the desired key, and the function returns TRUE if the key is down and FALSE if it is up. This can test for <shift> and <control> being pressed on their own, unlike GET/INKEY$ which need a character value,
IF INKEY(-a) AND INKEY(-b) AND INKEY(-c) returns FALSE unless all three keys identified by a, b and c are concurrently depressed.
But I digress, your input routine would typically test for the pressing of the arrow keys to modify the coordinate variables (and set limits to stop them exceeding the screen or viewing window) and a confirmation key like <space> or <return> to perform an action like selecting a game piece to move or place down.
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.