Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
Dim ref As Reflector
ref.Target = ref.GetActivity
ref.Target = ref.RunMethod("getWindow")
ref.Target = ref.RunMethod("getAttributes")
Dim current As Float = ref.GetField("screenBrightness")
If KeyCode = KeyCodes.KEYCODE_VOLUME_UP AND Round2(current,1) < 1 Then
current = current + 0.1
Else If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN AND Round2(current,1) > 0.1 Then
current = current - 0.1
Else If KeyCode <> KeyCodes.KEYCODE_VOLUME_UP AND KeyCode <> KeyCodes.KEYCODE_VOLUME_DOWN Then
Return False
End If
Log(current)
Log(Round2(current,1))
p.SetScreenBrightness(Min(1, Max(0.01, current)))
Return True
End Sub