I want to use SHIFT key to control how scroll event is acting.
Unfortunately ..RunMethod("getDeltaY", Null) return 0 when SHIFT key is pressed.
This is a normal behavior?
Dim jo As JavaObject = MainForm.RootPane
Dim e As Object = jo.CreateEventFromUI("javafx.event.EventHandler", "scroll", Null)
jo.RunMethod("setOnScroll", Array(e))
Dim r As Reflector
r.Target = MainForm.RootPane
r.AddEventFilter("KeyDown", "javafx.scene.input.KeyEvent.KEY_PRESSED")
r.AddEventFilter("KeyUp", "javafx.scene.input.KeyEvent.KEY_RELEASED")
Scroll wheel handling:
Sub Scroll_Event(MethodName As String, Args() As Object) As Object
Dim scrollevent As JavaObject = Args(0)
log(scrollevent.RunMethod("getDeltaY", Null))
Return Null
End Sub
Keyboard handling:
Sub KeyDown_Filter(e As Event)
Dim r As Reflector
r.Target = e
Dim keycode As String = r.RunMethod("getCode")
log(keycode)
e.Consume
Return
Sub KeyUp_Filter(e As Event)
Dim r As Reflector
r.Target = e
Dim keycode As String = r.RunMethod("getCode")
e.Consume
End Sub
Returned value is +/- 13 for slow scrolling without pressing SHIFT (or pressing any other key), but 0 if SHIFT is pressed.
Tried your suggestion, but the issue seems to be the same. When SHIFT key is pressed, returned value for getDeltaY is still 0.
I was not able to find another way to get scroll direction without using getDeltaY.
Paste this into a new project with jReflection and JavaObject libraries selected:
B4X:
#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
' MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Dim R As Reflector
R.Target = MainForm.RootPane
R.AddEventFilter("RPScroll","javafx.scene.input.ScrollEvent.SCROLL")
End Sub
Private Sub RPScroll_Filter (E As Event)
Dim MouseEvent As JavaObject = E
If MouseEvent.RunMethod("isShiftDown",Null) Then
Log("Shift Down")
Else
Log("Shift Not Down")
End If
End Sub
It appears that the shift key is reserved to control the scroll direction, which doesn't mean you cant use it, it just means use getDeltaX.
Something like:
B4X:
Private Sub RPScroll_Filter (E As Event)
Dim MouseEvent As JavaObject = E
If MouseEvent.RunMethod("isShiftDown",Null) Then
Log("Shift Down")
Log(MouseEvent.RunMethod("getDeltaX", Null))
Else
Log("Shift Not Down")
Log(MouseEvent.RunMethod("getDeltaY", Null))
End If
End Sub
Unless you want to control both directions, in which case avoid using the shift key for anything else.