Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacExtras/Apple Remote/AppleRemote Receiver
Function:
Required plugins for this example: MBS ComputerControl Plugin, MBS MacExtras Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacExtras/Apple Remote/AppleRemote Receiver
This example is the version from Mon, 22th Feb 2015.
Project "AppleRemote Receiver.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
Function FileAboutARRIMouseMover() As Boolean about.Show End Function
End Class
Class Window1 Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() self.Minimize End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() QuitWindow.show End EventHandler
End Control
EventHandler Sub Close() quit End EventHandler
EventHandler Function KeyDown(Key As String) As Boolean //Dim k As new KeyCodesMBS //MsgBox str(asc(Key)) + chr(13) + str(k.AsciiToKeyCode(asc(Key))) End EventHandler
EventHandler Sub Open() Dim x, y As integer, p As PresskeyMBS addAppleRemoteListener self p= new PresskeyMBS //x = System.MouseX //y = System.MouseY x = (self.left + PushButton1.left) + (PushButton1.width/2) y = (self.top + PushButton1.top-6) + (PushButton1.height/2) p.MouseMove x,y End EventHandler
Sub RemoteButtonPressed(button As integer, released As boolean) // Part of the AppleRemoteReceiver interface. ' Initialize x and y coordinates ' initialize PresskeyMBS and KeyCodesMBS for Keyboard and mouse Functionality Dim x, y As integer, p As PresskeyMBS, k As KeyCodesMBS ' make new PresskeyMBS (For Mouse (and some Keyboard) Functionality) p= new PresskeyMBS ' make new KeyCodesMBS (For Keyboard Functionality) k = new KeyCodesMBS if mReleased = TRUE AND button = AppleRemoteMBS.kRemoteButtonMenu then isSleepingQuit = not isSleepingQuit end if if isSleepingQuit = FALSE then if button = AppleRemoteMBS.kRemoteButtonPlaySleep then if mReleased = TRUE then QuitWindow.Show end if end if if button = AppleRemoteMBS.kRemoteButtonMenuHold then mReleased = not mReleased end if end if if button = AppleRemoteMBS.kRemoteButtonLeft or button = AppleRemoteMBS.kRemoteButtonLeftHold then if AppleRemoteModule.keyMode = kKeyModeCursor then x=system.mouseX y=system.mousey x=x-5 if button = AppleRemoteMBS.kRemoteButtonLeftHold then x = 0 p.MouseMoveClick x, y, TRUE else pressKey(28, k.AsciiToKeyCode(70)) end if end if if button = AppleRemoteMBS.kRemoteButtonRight or button = AppleRemoteMBS.kRemoteButtonRightHold then if AppleRemoteModule.keyMode = kKeyModeCursor then x=system.mouseX y=system.mousey x=x+5 if button = AppleRemoteMBS.kRemoteButtonRightHold then x = screen(0).Width p.MouseMoveClick x, y, TRUE else pressKey(29, k.AsciiToKeyCode(66)) end if end if if button = AppleRemoteMBS.kRemoteButtonVolumePlus then if AppleRemoteModule.keyMode = kKeyModeCursor then x=system.mouseX y=system.mousey y=y-5 p.MouseMoveClick x, y, TRUE else pressKey(30, k.AsciiToKeyCode(77)) end if end if if button = AppleRemoteMBS.kRemoteButtonVolumeMinus then if AppleRemoteModule.keyMode = kKeyModeCursor then x=system.mouseX y=system.mousey y = y+5 p.MouseMoveClick x, y, TRUE else pressKey(31, k.AsciiToKeyCode(72)) end if end if if button = AppleRemoteMBS.kRemoteButtonMenu then if AppleRemoteModule.keyMode = kKeyModeKeyboard then pressKey(51, k.AsciiToKeyCode(8)) else p.MouseMoveClick system.MouseX, system.mouseY, true p.MouseMoveClick system.MouseX, system.mouseY, false ' 1 click p.MouseMoveClick system.MouseX, system.mouseY, true ' + p.MouseMoveClick system.MouseX, system.mouseY, false ' 1 click ' 2 clicks = 1 Double Click end if end if if isSleepingQuit = TRUE then if button = AppleRemoteMBS.kRemoteButtonMenuHold then if AppleRemoteModule.keyMode <> kKeyModeCursor then MsgBox "Switching to cursor mode" AppleRemoteModule.keyMode = kKeyModeCursor else MsgBox "Switching to Keyboard mode" AppleRemoteModule.keyMode = kKeyModeKeyboard end if end if end if if button = AppleRemoteMBS.kRemoteButtonPlay then p.MouseMoveClick system.MouseX, system.mouseY, true p.MouseMoveClick system.MouseX, system.mouseY, false end if End Sub
Sub pressKey(charCode As Integer, keyCode As integer) Dim p As new PresskeyMBS p.Charcode = charCode p.Keycode = keyCode p.press End Sub
Property isSleepingQuit As boolean
Property mReleased As boolean
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem FileAboutARRIMouseMover = "About ARRI Mouse Mover"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class AppleRemoteHandler Inherits AppleRemoteMBS
EventHandler Sub ButtonPressed(ButtonID as integer, PressedDown as boolean, clickCount as Integer) Dim np As Boolean np = not PressedDown Select case ButtonID case kRemoteButtonVolumePlus ' Up Button sendToListeners kRemoteButtonVolumePlus, np case kRemoteButtonVolumeMinus ' Down Button sendToListeners kRemoteButtonVolumeMinus, np case kRemoteButtonMenu ' Menu Button sendToListeners kRemoteButtonMenu, np case kRemoteButtonPlay ' Play Button sendToListeners kRemoteButtonPlay, np case kRemoteButtonRight ' Right Button sendToListeners kRemoteButtonRight, np case kRemoteButtonLeft ' Left Button sendToListeners kRemoteButtonLeft, np case kRemoteButtonRightHold ' Right Button (Hold) sendToListeners kRemoteButtonRightHold, np case kRemoteButtonLeftHold ' Left Button (Hold) sendToListeners kRemoteButtonLeftHold, np case kRemoteButtonMenuHold ' Menu Button (Hold) sendToListeners kRemoteButtonMenuHold, np case kRemoteButtonPlaySleep ' Play Button (Hold Time To Sleep Computer) sendToListeners kRemoteButtonPlaySleep, np case kRemoteControlSwitched ' Control Switched sendToListeners kRemoteControlSwitched, np else MsgBox "Unknown Apple Remote Button Pressed" end Select End EventHandler
Protected Sub SendToListeners(buttonCode As integer, released As boolean) me.SendPressToListeners buttonCode, released End Sub
End Class
Module AppleRemoteModule
Const kKeyModeCursor = 0
Const kKeyModeKeyboard = 1
Sub SendPressToListeners(Extends arH As AppleRemoteHandler, button As integer, released As Boolean) Dim arL As AppleRemoteReceiver for each arL in listeners arL.RemoteButtonPressed button, released next End Sub
Sub addAppleRemoteListener(receivers As AppleRemoteReceiver) initRemote listeners.Append receivers Exception MsgBox "Exception" End Sub
Sub destroyRemote() if AppleRemote <> nil then stopListening AppleRemote = nil end if End Sub
Function getRemote() As appleRemoteHandler return AppleRemote End Function
Sub initRemote() if appleRemote <> nil then if not isAppleRemoteAvaliable then destroyRemote else if AppleRemote.ListeningToRemote = FALSE then AppleRemote.startListening end if end if else AppleRemote = new AppleRemoteHandler if not isAppleRemoteAvaliable then destroyRemote else AppleRemote.startListening end if end if End Sub
Function isAppleRemoteAvaliable() As boolean Dim avaliable As Boolean if appleRemote <> nil then return AppleRemote.remoteAvailable else AppleRemote = new AppleRemoteHandler avaliable = AppleRemote.RemoteAvailable destroyRemote return avaliable end if End Function
Sub stopListening() if AppleRemote.ListeningToRemote = TRUE then AppleRemote.stopListening end if End Sub
Property Protected appleRemote As AppleRemoteHandler
Property keyMode As integer
Property Protected listeners() As AppleRemoteReceiver
End Module
Interface AppleRemoteReceiver
Sub RemoteButtonPressed(button As integer, released As boolean)
Note "Copyright and other info"
© Jordan Pittman © Monkey Bread Software Hello, My Name is Jordan Pittman, I based this project off of MBS's AppleRemoteMBS Plugin/Plugin Part. This Class Allows you to implement an Interface and all the background code will do the rest. Anyway, the Interface (AppleRemoteReceiver) has 1 method, RemoteButtonPressed(button As Integer) buttons are defined as ants in the AppleRemoteModule but here is the list kRemoteButtonUp = 1 kRemoteButtonDown = 2 kRemoteButtonMenu = 3 kRemoteButtonPlay = 4 kRemoteButtonRight = 5 kRemoteButtonLeft = 6 kRemoteButtonHoldRight = 7 kRemoteButtonHoldLeft = 8 kRemoteButtonHoldMenu = 9 kRemoteButtonPlaySleep = 10 kRemoteControlSwitched = 11 kRemoteButtonHoldUp = 12 kRemoteButtonHoldDown = 13
End Interface
Class QuitWindow Inherits Window
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() secPassed = secPassed +1 if secPassed = secWait then me.mode = 0 quit else setTitleDetails end if End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
EventHandler Sub Open() baseTitle = self.title secPassed = 0 secWait = 25 setTitleDetails End EventHandler
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() timer1.mode = 0 self.close End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() timer1.mode = 0 baseTitle = "" secPassed = 0 secWait = 0 quit End EventHandler
End Control
EventHandler Sub Open() me.SetFocus window1.mReleased = FALSE Dim x, y As integer, p As PresskeyMBS p= new PresskeyMBS x = (self.left + PushButton2.left) + (PushButton2.width/2) y = (self.top + PushButton2.top-6) + (PushButton2.height/2) p.MouseMove x,y End EventHandler
Sub setTitleDetails() Dim nBT As string, TimeLeft As integer = (secWait - secPassed) nBT = baseTitle.Replace("#(x)", str(TimeLeft)) if TimeLeft = 1 then nBT = nBT.Replace("Seconds", "Second") self.title = nBT StaticText1.Text = nBT End Sub
Property baseTitle As string
Property secPassed As Integer
Property secWait As Integer
End Class
Class About Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacExtras Plugin.




Links
MBS Xojo Plugins