Platforms to show: All Mac Windows Linux Cross-Platform
/ComputerControl/Write something
Required plugins for this example: MBS ComputerControl Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /ComputerControl/Write something
This example is the version from Sun, 17th Mar 2012.
Project "Write something.xojo_binary_project"
Class Window1 Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
select case counter
case 0
call RemoteControlMBS.LinuxPressShiftKey true
call RemoteControlMBS.LinuxPressKey 43
call RemoteControlMBS.LinuxPressShiftKey false
case 1
call RemoteControlMBS.LinuxPressKey 26 // e
case 2
call RemoteControlMBS.LinuxPressKey 46 // l
case 3
call RemoteControlMBS.LinuxPressKey 46 // l
case 4
call RemoteControlMBS.LinuxPressKey 32 // o
case 5
call RemoteControlMBS.LinuxPressKey 65 // space
case 6
call RemoteControlMBS.LinuxPressShiftKey true
call RemoteControlMBS.LinuxPressKey 25 // w
call RemoteControlMBS.LinuxPressShiftKey false
case 7
call RemoteControlMBS.LinuxPressKey 32 // o
case 8
call RemoteControlMBS.LinuxPressKey 27 // r
case 9
call RemoteControlMBS.LinuxPressKey 46 // l
case 10
call RemoteControlMBS.LinuxPressKey 40 // d
case 11
call RemoteControlMBS.LinuxPressKey 36 // enter
case 20
me.mode=0
end select
counter=counter+1
End EventHandler
End Control
Control RoundRectangle1 Inherits RoundRectangle
ControlInstance RoundRectangle1 Inherits RoundRectangle
EventHandler Function MouseDown(X As Integer, Y As Integer) As Boolean
Return true
End EventHandler
EventHandler Sub MouseUp(X As Integer, Y As Integer)
if targetwin32 then
Writewin
elseif targetmacho then
writemac
elseif targetlinux then
writelinux
else
msgBox "not supported"
end if
End EventHandler
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
EventHandler Sub Open()
editfield1.setfocus
End EventHandler
Protected Function ScanCode(x as integer) As integer
// just a function to keep lines shorter
return remoteControlMBS.WinVirtualKeyCodeToScanCode(virtualCode(x))
End Function
Protected Function VirtualCode(x as integer) As integer
dim shift,control,alt as boolean
dim vk as integer
if remoteControlMBS.WinVirtualKeyForASCII(x,vk,shift,control,alt) then
return vk
end if
End Function
Sub Write()
// old code, deprecated
dim p as PresskeyMBS
p=new PresskeyMBS
p.shift=true
p.Charcode=asc("H")
p.Keycode=4
p.virtualCode=-1
p.press
p.shift=false
p.Charcode=asc("e")
p.Keycode=14
p.virtualCode=-1
p.press
p.Charcode=asc("l")
p.Keycode=&h25
p.virtualCode=-1
p.press
p.press
p.Charcode=asc("o")
p.virtualCode=-1
p.Keycode=&h1F
p.press
p.Charcode=asc(" ")
p.Keycode=&h31
p.virtualCode=-1
p.press
p.shift=True
p.Charcode=asc("W")
p.virtualCode=-1
p.Keycode=&h0D
p.press
p.shift=false
p.Charcode=asc("o")
p.virtualCode=-1
p.Keycode=&h1F
p.press
p.Charcode=asc("r")
p.Keycode=&h0F
p.virtualCode=-1
p.press
p.Charcode=asc("l")
p.virtualCode=-1
p.Keycode=&h25
p.press
p.Charcode=asc("d")
p.virtualCode=-1
p.Keycode=&h02
p.press
p.charcode=13
p.virtualCode=-1
p.keycode=&h24
p.press
End Sub
Protected Sub WriteLinux()
// we need a timer
// if the events come too fast, RB will get the keys in the wrong order
// gedit does not have this trouble receiving events
counter=-200 // delay 2 seconds
timer1.mode=2
End Sub
Protected Sub WriteMac()
call RemoteControlMBS.MacPressShiftKey true
call RemoteControlMBS.MacPressKey asc("H"),4
call RemoteControlMBS.MacPressShiftKey false
call RemoteControlMBS.MacPressKey asc("e"),14
call RemoteControlMBS.MacPressKey asc("l"),&h25
call RemoteControlMBS.MacPressKey asc("l"),&h25
call RemoteControlMBS.MacPressKey asc("o"),&h1F
call RemoteControlMBS.MacPressKey asc(" "),&h31
call RemoteControlMBS.MacPressShiftKey true
call RemoteControlMBS.MacPressKey asc("W"),&h0D
call RemoteControlMBS.MacPressShiftKey false
call RemoteControlMBS.MacPressKey asc("o"),&h1F
call RemoteControlMBS.MacPressKey asc("r"),&h0F
call RemoteControlMBS.MacPressKey asc("l"),&h25
call RemoteControlMBS.MacPressKey asc("d"),&h02
call RemoteControlMBS.MacPressKey 13, &h24 // enter
End Sub
Protected Sub WriteWin()
call RemoteControlMBS.WinPressShiftKey true
call RemoteControlMBS.WinPressKey VirtualCode(asc("H")),ScanCode(asc("H"))
call RemoteControlMBS.WinPressShiftKey false
call RemoteControlMBS.WinPressKey VirtualCode(asc("e")),ScanCode(asc("e"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("l")),ScanCode(asc("l"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("l")),ScanCode(asc("l"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("o")),ScanCode(asc("o"))
call RemoteControlMBS.WinPressKey VirtualCode(asc(" ")),ScanCode(asc(" "))
call RemoteControlMBS.WinPressShiftKey true
call RemoteControlMBS.WinPressKey VirtualCode(asc("W")),ScanCode(asc("W"))
call RemoteControlMBS.WinPressShiftKey false
call RemoteControlMBS.WinPressKey VirtualCode(asc("o")),ScanCode(asc("o"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("r")),ScanCode(asc("r"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("l")),ScanCode(asc("l"))
call RemoteControlMBS.WinPressKey VirtualCode(asc("d")),ScanCode(asc("d"))
call RemoteControlMBS.WinPressKey VirtualCode(13), ScanCode(13) // enter
End Sub
Property Protected counter As integer
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project
The items on this page are in the following plugins: MBS ComputerControl Plugin.