I've got it working at last!!!!!!
<Brief pause as Robert the Robot does one hundred somersaults around the room in jubilation>
<Longer pause as Robert the Robot wonders why there are now a load of wheels and gears all over the floor>
I'd stumbled across one way of eradicating the red line when shift/upkey was pressed - I accidentally set the CanPressKey(0) array to always be zero. But the single keystrokes wouldn't work - they were only detected if CanPressKey(0) = 1.
I had to reset the canPressKey(0) at some point, and after a lot of fiddling and rearranging,I produced this:
rem By Robert the Robot
rem It Works!!!!!!
hide mouse
sync on
rem Array governing whether or not a single key can be pressed
Dim CanPressKey(0) : CanPressKey(0) = 1
rem Array holding scancode data
Dim keyCom(3, 2)
KeyCom(1, 0) = 1
KeyCom(1, 1) = 200
KeyCom(1, 2) = 0
KeyCom(2, 0) = 2
KeyCom(2, 1) = 200
KeyCom(2, 2) = 42
KeyCom(3, 0) = 2
KeyCom(3, 1) = 29
KeyCom(3, 2) = 42
DO
rem If this was a function, would I just use ExitFunction in place of GoTo FinishedCheckingkeys
rem returning the value of T to the main program and acting accordingly?
rem Check for two keys
For T = 1 to 3
If KeyCom(T, 0) = 2
If Key Control(T, KeyCom(T, 1), KeyCom(T, 2)) = 1
Select T
Case 1
rem random red lines
ink rgb(255, 0, 0),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
GoTo FinishedCheckingkKeys
EndCase
Case 2
rem random green lines
ink rgb(0,255,0),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
GoTo FinishedCheckingkKeys
EndCase
Case 3
rem random blue lines
ink rgb(35, 40, 255),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
GoTo FinishedCheckingkKeys
Endcase
EndSelect
endif
endif
Next T
rem Check for one key
If KeyCom(1, 0) = 1
rem random red lines
If Key Control(1, KeyCom(1, 1), KeyCom(1, 2)) = 1
ink rgb(255, 0, 0),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
endif
endif
If KeyCom(2, 0) = 1
rem random green lines
If Key Control(2, KeyCom(2, 1), KeyCom(2, 2)) = 1
ink rgb(0,255,0),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
endif
endif
If KeyCom(3, 0) = 1
rem random blue lines
If Key Control(3, KeyCom(3, 1), KeyCom(3, 2)) = 1
ink rgb(35, 40, 255),0 : line rnd(639),rnd(479),rnd(639),rnd(479)
endif
endif
FinishedCheckingkKeys:
sync
LOOP
rem work out which key is pressed
Function Key Control(Commandno, keyone, keytwo)
pressed = 0
A = keystate(keyone)
B = keystate(keytwo)
if keycom(CommandNo, 0) = 1 and CanPressKey(0) = 1
If A+B = 1 and A=1 then Pressed = 1
ExitFunction Pressed
endif
if keycom(CommandNo, 0) = 2
If A+B = 2 then Pressed = 1 : CanPressKey(0) = 0
endif
if pressed = 0 then Canpresskey(0) = 1
EndFunction Pressed
It only works if you check for two-key and then one-key combinations (don't ask me why, I'm still trying to figure it out myself). The case statements check which two key combination is being pressed, and if it finds one that is, it bypasses all other keyboard checks.
The only thing is, I can't help feeling the code is a bit
messy. I'm trying to condense the two-key case statment block into a single function, but is it possible to condense the whole thing down? I could do with some help here, and on Functions in general - I never could quite get the hang of them...
@ Latch
Your code was a very good idea, but I was a little bothered by the fact that your example seemed to hard-code in how many keys would be assigned to each command. The way it stands at the moment, if you wanted to draw red lines then whatever you did, you'd press one key. If you wanted green lines, you'd always have to press two keys.
I did try to change that, but I wound up covering the screen with red and green lines. Oops...
On our way 'ome, on our way 'ome...