I needed to trap/execute action depending on the pressed Arrow Key in Canvas1.MouseDown.
I wasted my time (without Internet for while) because I had a problem with my code and I was not sure about the arrow values on the keyboard/Canvas.KeyDown(Key).
The used code is:
// Read the image number #…
If key = Chr(28) And Img_Nbr > 1 Then // Left Arrow
Img_Nbr = Img_Nbr - 1
ElseIf key = Chr(29) And Img_Nbr < Img_Cnt Then // Right Arrow
Img_Nbr = Img_Nbr + 1
ElseIf key = Chr(30) Then // Up Arrow
Img_Nbr = 1
ElseIf key = Chr(31) Then // Down Arrow
Img_Nbr = Img_Cnt
Else
System.DebugLog "Unknow Key" // *
End If
I rarely get the Left Arrow fired, but the key works fine elsewhere.
Is there’s something wrong ?
I was not able to transform Key to a decimal value… tired !
select case ask( Key )
case Key_Left
case Key_Right
// etc
end select
My key constants are as follows:
Private Const KEY_BACKSPACE as Number = 8
Private Const KEY_DOWNARROW as Number = 31
Private Const KEY_ESCAPE as Number = 27
Private Const KEY_LEFTARROW as Number = 28
Private Const KEY_PAGEDOWN as Number = 12
Private Const KEY_PAGEUP as Number = 11
Private Const KEY_RETURN as Number = 13
Private Const KEY_RIGHTARROW as Number = 29
Private Const KEY_TAB as Number = 9
Private Const KEY_UPARROW as Number = 30
If you are acting on the key then you should “Return True” from the event, otherwise other elements start reacting to keys.
I find it easier to use:
You are right. But at 7 in the morning of a white night, one can took the other way.
Thank you professor. But System.DebugLog display nothing for the left arrow ley press. That means it # is ignored (or wrong) or something else (what ?) happened.
That is the object of my question.
I started the If block testing only Key. I added the second condition later, to avoid asking a file that does not exists: I use aPict = Picture.Open(Img_FI.Item(Img_Nbr)) to load the image file. The FolderItem is a Reference to a Folder with images.
The testing folders have > 20 and > 200 files each, and: Img_Nbr is declared as Static, init at 1 (else I get a crash).
Apparently Left Arrow is Chr(28) and have to work in the IDE.
I even clear the Xojo Cache.
Old Horse, I told you ( for the record, I started with REALbasic in may 1998…ß…) and buy version 1 sometimes later when it was available.
And, yes, I can make mistakes
A bad key, sometimes (sometimes more bad than some other times), I am starting to think.
BTW: I used KeyUp. I copied the code to KeyDown an hour ago and set the image resize (I keep the W/H ratio) correctly (it was time). I need to Sort set the files in an Array and Sort them, so I can see them “in order”… (1…200 or by dates depend on the test files).
My previous MBP had something like four keyboard replacements under AppleCare for stuck/non-working keys. My current 2022 model is much much better but occasionally has issues that seem to fix themselves over time. Concidentally, I think left-arrow was the most recent one to go flaky, but now it’s working