How to detect a keys combination on a Canvas keyUp event?
The code detects either “R” or OptionKey but no way of detect both.
if Keyboard.OptionKey then delta is -60 but then key is not R and, vice versa if R is checked first
Var delta As Integer
delta = 60
If Keyboard.OptionKey Then
delta = - 60
End If
If key = "R" Then
RotateDegrees = RotateDegrees + delta
If RotateDegrees > 300 Or RotateDegrees < 0 Then
RotateDegrees = 0
End If
End If
DegreeLabel.Text = RotateDegrees.ToString
Refresh
@RudolfJ
i have only luch with shift key at windows 11.
somehow keys are in use by os or nvidia.
Function KeyDown(key As String) Handles KeyDown as Boolean
Var delta As Integer = TextField1.Text.Val
Var degree As Double = 3.14 / 180
If key = "R" Then
If Keyboard.AsyncShiftKey Then delta = -delta
Var w As Integer =(s.Rotation/degree)+delta
If w >360 Then w = w -360
s.Rotation = w * degree
canvas1.refresh
End If
End Function
The code on KeyUP event does not work but the same code on KeyDown it works.
Using the Keyboard.AsyncOptionKey does not work
Using the Keyboard.AsyncCommandKey (or Keyboard.CommandKey) does work
So, command key plus R on keyDown event works. (should be a reason for…)
i am a fan of screen icons or context menu instead of key combinations.
or i would use r for rotate modus and then left/right cursor intuitively,
same for m = move and then cursor keys.
Your keyboard certainly doesn’t produce a “R” when you press option-r. For instance, mine produces a ® symbol. Therefore, it’s logical to expect key to not be “r”, but rather the actual symbol (like any other press would make).
One trick that works for “R” (but wouldn’t for some other keys) is to check the physical key. It turns out that “R” is at the same location for all layouts (which wouldn’t be the case for “y”, for instance), so you can use “if keyboard.AsyncKeyDown(15) then” to check for the “r” key.
Other advices already given would work too, like adding an events monitor, but keyboard.AsyncKeyDown is a built-in solution.