I know this is basic so my apologies. I do understand the usage of Select Case but I can’t quite solve this issue in regards to pressing a key.
I’m drawing a simple xy graph in a canvas. This part is working fine. I’m able to pan/scroll/zoom using the keyboard arrow keys + a modifier key when required. What I’ve come up with is working ok but there is an issue with zoom, which after a few hours mucking around I’ve realised were the issue lies - I think.
It all happens in the Canvas KeyDown Event. Here’s the code:
If Keyboard.AsyncKeyDown(&h7B) then
scrollX = scrollX + (-scrollIncrementX) //Scroll LeftArrow
If Keyboard.AsyncKeyDown(&h7C) then //Scroll RightArrow
scrollX = scrollX + (scrollIncrementX)
If Keyboard.AsyncKeyDown(&h7E) then //Scroll UpArrow
scrollY = scrollY + (-scrollIncrementY)
If Keyboard.AsyncKeyDown(&h7D) then //Scroll DownArrow
scrollY = scrollY + (scrollIncrementY)
If keyboard.AsyncShiftKey AND Keyboard.AsyncKeyDown(&h7E) then //Shift+UpArrow ZOOM IN
graphScaleFactor = graphScaleFactor*2
If keyboard.AsyncShiftKey AND Keyboard.AsyncKeyDown(&h7D) then //Shift+DownArrow ZOOM OUT
graphScaleFactor = graphScaleFactor/2
I’ve used blocks of If/End If statements and now understand what’s happening. When I press the shift key for zoom, then press the up arrow, both events are evaluated. ie. Up Arrow first, Then Shift+UpArrow. In the old days I would have inserted a GOTO statement before each End If to break out… Oh dear
I did originally consider using Select Case but I thought that it wouldn’t work with the boolean operator AND. As in this pseudo code:
myKeyPress$ = INKEY$
Select Case myKeyPress$
Up Arrow, break out...
Case keyboard.AsyncShiftKey AND Keyboard.AsyncKeyDown(&h7E)
Shift+UpArrow, break out...
Now Methods/SubPrograms go here...
Sorry about the mixture of code syntax but hopefully it puts the point accross.
If it was just variables I could work it out, but using Keyboard.AsyncKeyDown is throwing me off a bit. This has become a sticking point and I can’t move on with the rest of the program until this is resolved.
Happy to hear any other ideas as well.