WMKS_SDK_Programming_Guidex Html Console Sdk 210 Programmer Guide
User Manual:
Open the PDF directly: View PDF .
Page Count: 19
![](asset-1.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page1
VMware HTML Console SDK
Programming Guide
For vSphere 5.5 and later (General Availability)
and vCloud Director (Tech Preview)
October2016
![](asset-2.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page2
VMwareHTMLConsoleSDK
ProgrammingGuide
TableofContents
SupportedBrowsers(includingoniOSandAndroid)..........................................................4
StepsforusingtheHTMLConsoleSDKAPI.........................................................................4
Placingtheconsoleonawebpage...............................................................................................................................5
ConnectingtoaRemoteVM.............................................................................................................................................5
DisconnectandDestroy.....................................................................................................................................................6
ThefactorymethodoftheWMKS......................................................................................6
createWMKS()........................................................................................................................................................................6
CreateOptions........................................................................................................................................................................6
LikewebMKSembeddedinthevSpherewebclient,WMKSalsohasmultipleoptionsthatcanbe
usedtocontrolitsbehavior.HereisthecomparisonbetweentheSDKandwebMKSembeddedin
thevSpherewebclient:.......................................................................................................................................................6
rescale.........................................................................................................................................................................................6
position.......................................................................................................................................................................................7
changeResolution..................................................................................................................................................................7
audioEncodeType..................................................................................................................................................................7
useNativePixels.......................................................................................................................................................................7
useUnicodeKeyboardInput................................................................................................................................................7
useVNCHandshake................................................................................................................................................................7
sendProperMouseWheelDeltas.......................................................................................................................................7
reverseScrollY.........................................................................................................................................................................7
retryConnectionInterval....................................................................................................................................................8
ignoredRawKeyCodes..........................................................................................................................................................8
fixANSIEquivalentKeys.......................................................................................................................................................8
keyboardLayoutId.................................................................................................................................................................8
VCDProxyHandshakeVmxPath........................................................................................................................................9
HandlingWMKSEvents....................................................................................................10
ListofWMKSEvents........................................................................................................................................................10
connectionstatechange....................................................................................................................................................10
screensizechange................................................................................................................................................................10
fullscreenchange.................................................................................................................................................................10
error.........................................................................................................................................................................................10
Keyboardledschanged......................................................................................................................................................11
heartbeat................................................................................................................................................................................11
audio.........................................................................................................................................................................................11
copy...........................................................................................................................................................................................11
toggle.......................................................................................................................................................................................11
SettingHandlersforWMKSEvents...........................................................................................................................11
register()................................................................................................................................................................................11
unregister()...........................................................................................................................................................................12
GeneralAPIs.........................................................................................................................................................................12
getVersion()..........................................................................................................................................................................12
![](asset-3.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page3
getConnectionState().......................................................................................................................................................12
Lifecycle‐relatedAPIs......................................................................................................................................................13
connect()................................................................................................................................................................................13
disconnect()..........................................................................................................................................................................13
destroy().................................................................................................................................................................................13
Display‐relatedAPIs.........................................................................................................................................................13
setRemoteScreenSize()....................................................................................................................................................13
getRemoteScreenSize()...................................................................................................................................................14
updateScreen()....................................................................................................................................................................14
Full‐screen‐relatedAPIs.................................................................................................................................................14
canFullScreen()...................................................................................................................................................................14
isFullScreen().......................................................................................................................................................................15
enterFullScreen()...............................................................................................................................................................15
exitFullScreen()...................................................................................................................................................................15
Input‐relatedAPIs.............................................................................................................................................................15
sendInputString()...............................................................................................................................................................15
sendKeyCodes()...................................................................................................................................................................15
sendCAD()..............................................................................................................................................................................16
Mobile‐relatedAPIs..........................................................................................................................................................16
enableInputDevice().........................................................................................................................................................16
disableInputDevice()........................................................................................................................................................16
showKeyboard()..................................................................................................................................................................16
hideKeyboard()...................................................................................................................................................................16
toggleExtendedKeypad()................................................................................................................................................17
toggleTrackpad()...............................................................................................................................................................17
toggleRelativePad()..........................................................................................................................................................17
Option‐relatedAPIs..........................................................................................................................................................18
setOption().............................................................................................................................................................................18
Appendix................................................................................................................................................................................18
ConstantsusedinWMKS...............................................................................................................................................18
![](asset-4.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page4
HTMLConsole(WMKS)SDK
Overview
TheHTMLConsoleSDKisaJavaScriptlibraryimplementedbasedonwebmks(WMKS),
which can provide mouse, keyboard, touch input processing and handling as well as
screenupdatesandcursorchangestoadesktopsessionfromabrowser.Applications
runninginthebrowsercanuseJavaScripttoaccessvirtualmachineconsolefunctions
byusingtheHTMLConsoleSDKAPI.
TheHTMLConsoleSDKAPIcontainsvariousmethodsthatcanbeused toconnectto
and communicate with a virtual machine. It also triggers eventstonotifyusersof
changestothevirtualmachine’sstate.Youcanusethesemethodsandcallbackstogive
enduserstheabilitytoremotelymanageavirtualmachinefromanysystemwiththe
appropriatewebbrowserandoperatingsystem.
SupportedBrowsers(includingoniOSandAndroid)
InternetExplorer10+
Firefox24+
Chrome30+
Safari6.1+
StepsforusingtheHTMLConsoleSDKAPI
To use the HTML Console SDK API, a web‐based application must typically do the
followingthings:
1. LoadtheHTMLConsoleSDKJavaScriptlibraryfiles.
2. CreatetheWMKScoreobjectbyusingthefactorymethodcreateWMKS()witha
givendivelementIDinthedocumentDOMandthecreateoptions.
3. RegisterJavaScriptcallbackstorespondtoWMKStriggeredEvents.
4. UsetheHTMLConsoleSDKconnect()methodtoconnecttoatarget virtual
machine.
5. Use the HTML Console SDK methods to interact with the connectedvirtual
machine.
6. UsetheHTMLConsoleSDKmethoddisconnect()todisconnecttheconnection(if
![](asset-5.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page5
active)andremovethewidgetfromtheassociatedelement.
Placingtheconsoleonawebpage
The HTML Console SDK is available in the Downloads section of www.vmware.com:
DriversandToolsforvSphere,vCloudDirector,vRealizeAutomation,andvCloudAir.
A minified wmks.min.js and an un‐minified wmks.js are both provided in each build.
TheHTMLConsoleSDKusesjQuerywidgettodisplaytheVMconsole,andtherefore
thejQueryrelatedlibraryneedstobeincludedfirst.Hereisanexample:
1. Include jQuery and jQuery UI Javascript components in script tags, and the
correspondingjQuerycssfileinlinkstylesheettag.
2. Include wmks.js (or wmks.min.js) in a script tag, and the wmks‐all.css in link
stylesheettag.
3. Provideadivwithanappropriateid.
4. CreatetheWMKScoreobjectwithfactorymethodWMKS.createWMKS().
5. BindthecallbacksforWMKSevents.
6. ConnectwiththeappropriatedestinationURL.
ConnectingtoaRemoteVM
ThewaystoconnecttoaremoteVM:
WMKSisusableasacomponentindeliveringapureweb‐basedconsoleconnectionto
vCenterServer‐managedVMsbyusinganintermediaryproxytohandle the
authenticationrequirements.
ConnecttotheVMusingthefollowingmethod:
<linkrel="stylesheet"type="text/css"href="wmks‐all.css"/>
<scripttype="text/javascript"src="jquery‐1.8.3.min.js"></script>
<scripttype="text/javascript"src="jquery‐ui.1.8.16.min.js"></script>
<scripttype="text/javascript"src="wmks.js"type="text/javascript"></script>
<script>
varwmks=WMKS.createWMKS("wmksContainer",{})
.register(WMKS.CONST.Events.CONNECTION_STATE_CHANGE,
function(event,data){
if(data.state==cons.ConnectionState.CONNECTED)
{
console.log("connectionstatechange:connected");
}
});
wmks.connect(“ws://127.0.0.1:8080”);
</script>
<divid=”wmksContainer”style=”position:absolute;width:100%;height:100%”></div>
wmks.connect(url);
![](asset-6.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page6
TheURLshouldbeinthisscheme:
DisconnectandDestroy
CallthiswhenyouaredonewiththeWMKScomponent.DestroyingtheWMKSwillalso
resultinadisconnect(ifactive)andremovethewidgetfromtheassociatedelement.
ThefactorymethodoftheWMKS
createWMKS()
ThisshouldbethefirstmethodwhenyouusetheHTMLConsoleSDK.Usingthis
methodgeneratesthewidget,whichcandisplaytheremotescreen,andthenreturnthe
WMKScoreobjectwhichcanusealltheHTMLConsoleSDKAPIstoconnecttoaVMand
performoperations.
MethodcreateWMKS(id,options)
Parameter1id(string):theidofdivelement,thiselementwouldbethe
containerofcanvaswhichusedtoshowremotescreen.
Parameter2options:(jsonobject):createoptionswouldaffectthe
behavior of the WMKS. Empty means “use all the default
options.”
ReturnValueTheWMKScoreobject,whichcouldusealltheWMKSAPIto
connecttoaVMandperformoperations.
ExampleCallvarwmks=WMKS.createWMKS(“container”,{});
CreateOptions
Like webMKS embedded in the vSphere web client, WMKS also has multiple options
thatcanbeusedtocontrolitsbehavior.HereisthecomparisonbetweentheSDKand
webMKSembeddedinthevSpherewebclient:
rescale
Boolean:defaultistrue,andindicateswhethertorescaletheremotescreentofitthe
container'sallocatedsize.
<ws|wss>://<host:port>/<path>/?<authenticationinfo>
![](asset-7.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page7
position
Anenum:couldbeanyvalueofWMKS.CONST.Position,defaultvalue is
WMKS.CONST.Position.CENTER. It indicates which position (centerortopleft)the
remotescreenshouldbeinthecontainer.
changeResolution
Boolean:defaultistrue.WhentheoptionchangeResolutionistrue,WMKSwouldsend
thechangeresolutionrequesttotheconnectedVM,withtherequested resolution
(width&height)beingthesameasthecontainer'sallocatedsize.
Thesethreeoptionsfollowaspecificorderofprocedurebasedontheirpriority.
1. Check changeResolution,andiftrue,webmkswouldsendthechange
resolutionrequesttotheconnectedVM.
2. Iftherequestfails,theoperationsrescaleandpositioncanbeusedtomake
thecorrespondingchanges.
audioEncodeType
It'sanenum:couldbeanyvalueofWMKS.CONST.AudioEncodeType.Itindicateswhich
typeofaudioencodemethodisbeingused:vorbis,opusoraac.
useNativePixels
Boolean:defaultisfalse.Enablestheuseofnativepixelsizesonthedevice.OniPhone
4+oriPad3+,turningthisonwillenable"Retinamode",whichprovidesmorescreen
spacefortheguest,makingeverythingappearsmaller.
useUnicodeKeyboardInput
Boolean:defaultisfalse.Foralltheuserinput,WMKScouldsendtwokindsmessageto
server:keyboardscancodes,orUnicode.HeretruemeansclientshoulduseUnicodeif
possible.
useVNCHandshake
Boolean:defaultistrue.EnablesastandardVNChandshake.Thisshouldbeusedwhen
theendpointisusingstandardVNCauthentication.Settofalseifconnectingtoaproxy
thatauthenticatesthroughauthdanddoesnotperformaVNChandshake.
sendProperMouseWheelDeltas
Boolean:defaultisfalse.Previousversionsofthelibrarywouldnormalizemousewheel
eventdeltasintooneofthreevalues:[‐1,0,1].Whenthisissettotrue,theactualdeltas
fromthebrowseraresenttotheserver.
reverseScrollY
Boolean:defaultisfalse.Ifthisflagsettotrue,itwouldsendtheoppositevalueofthe
mousewheeltotheconnectedVM.
![](asset-8.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page8
retryConnectionInterval
Integer:defaultvalueis‐1.Theinterval(inmilliseconds)forreattemptingtoconnect
whenthefirstattempttosetupaconnectionbetweenwebclient and server fails. A
valuelessthan0means“won'tretry.”
ignoredRawKeyCodes
Array:defaultisempty.Allthesekeycodeswouldbeignoredandnotsendtotheserver.
fixANSIEquivalentKeys
Boolean:defaultisfalse.Enablesfixingofanynon‐ANSIUSlayoutskeyCodestomatch
ANSI US layout keyCodes equivalents. It attempts to fix any keys pressed where the
client's international keyboard layout has a key that is also present on the ANSI US
keyboard,butisinadifferentlocationordoesn'tmatchtheSHIFTorNOSHIFTstatusof
anANSIUSkeyboard.
keyboardLayoutId
String:defaultvalueis'en‐US’(U.S.English).Thisprovidesdifferentlanguagekeyboard
setupsfortheguest.Usersneedtodeterminewhatthekeyboardlayoutis,andkeepthe
remotedesktopandlocaldesktopkeyboardlayoutthesame.Inthisversionofthe
HTMLconsoleSDK,VMwaredoesnotsupportmobiledevices.There'retwokindsof
codesbeingsenttotheGuestOS.Whatwesupportforinternationalmappingis
vScancode.
InternetExplorer/Firefox/ChromearesupportedonWindows,andChrome/Safarion
Macaresupported.
Pleaseaddaselectlistinhtmlorusesomeotherwayforuserstochoosewhatlanguage
theyareusing.Injsfile,pleaseusesetOptionAPIasbelow:
<selectid="selectLanguage">
<optionvalue="en‐US">English</option>
<optionvalue="ja‐JP_106/109">Japanese</option>
<optionvalue="de‐DE">German</option>
<optionvalue="it‐IT">Italian</option>
<optionvalue="es‐ES">Spanish</option>
<optionvalue="pt‐PT">Portuguese</option>
<optionvalue="fr‐FR">French</option>
<optionvalue="fr‐CH">Swiss‐French</option>
<optionvalue="de‐CH">Swiss‐German</option>
</select>
![](asset-9.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page9
VCDProxyHandshakeVmxPath
String:defaultvalueisnull.PasstotheVNCprotocolwhenconnecting.vncProtocol
willrespondtoaconnectionrequestforaVMXpathwiththeprovided
VCDProxyHandshakeVmxPathwhenconnectingtovCloudDirector.
enableUint8Utf8
Boolean:defaultvalueisfalse.Iftheprojectdoesnothaveworkingsupportforthe
binaryprotocol,theenableUint8Utf8optionisneededtoenabletheolduint8utf8
protocol.
$('#selectLanguage').change(function(){
if(!wmks)return;
varkeyboardLayoutId=$(this).find(":selected").val();
wmks.setOption('keyboardLayoutId',keyboardLayoutId);
});
![](asset-a.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page10
HandlingWMKSEvents
ListofWMKSEvents
WebMKS generates events when the state of the currently connectedvirtualmachine
changes, or in response to messages from the currently connected virtual
machine.AlltheWMKSeventsarelistedinWMKS.CONST.Events.
Alltheeventhandlershavetwoparameters:eventanddata.EventisajQueryevent,
andalltheevents’specialparametersarestoredindata.
connectionstatechange
Theconnectionstatechangeeventisgeneratedinresponsetoachangeintheconnection
state,suchasfrom‘disconnected’to‘connecting’,from‘connecting’to‘connected’.
Parametersindata:
state:couldbeanyvalueinWMKS.CONST.ConnectionStatecanbe:
1. "connecting"
2. "connected"
3. "disconnected"
IfstateisWMKS.CONST.ConnectionState.CONNECTING,therearetwo more
parametersvvcandvvcSessionindata.
If state is WMKS.CONST. ConnectionState. DISCONNECTED, there are two more
parametersreasonandcodeindata.
screensizechange
Thescreensizechangeeventisgeneratedinresponsetochangesinthescreensizeofthe
currentlyconnectedvirtualmachine.
Parametersindata:
width:thewidth(inpixels)ofthecurrentlyconnectedvirtualmachine.
Height:theHeight(inpixels)ofthecurrentlyconnectedvirtualmachine.
fullscreenchange
The fullscreenChange event is generated when the WMKS console exits or enters
fullscreenmode.
Parametersindata:
isFullScreen:Boolean,truemeanenterfullscreen,falsemeansexitfullscreen.
error
The error event is generated when an error occurs, such as authentication failure,
websocketerrororprotocolerror.
Parametersindata:
errorType:couldbeanyvalueinWMKS.CONST.Events.ERROR:
1. AUTHENTICATION_FAILED:"authenticationfailed",
2. WEBSOCKET_ERROR:"websocketerror",
3. PROTOCOL_ERROR:"protocolerror"
![](asset-b.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page11
Keyboardledschanged
ThekeyboardledschangedeventisgeneratedwhentheremoteVM’skeyboardLEDlock
statechanges.
Parametersindata:
Dataisaninteger:1meansScrollLock,2meansNumLock,4meansCapsLock.
heartbeat
Theheartbeateventisgeneratedwhenaserversideheartbeatmessageisreceived.
Dataisanintegerthatindicatestheintervaloftheheartbeat.
audio
Theaudioeventisgeneratedwhenanaudiomessageisreceivedfromtheserver.
Parametersindata:
sampleRate
numChannels
containerSize
sampleSize
length
audioTimestampLo
audioTimestampHi
frameTimestampLo
frameTimestampHi
flags
data
copy
Thecopyeventisgeneratedwhentheserversendsacuttextevent.
Dataisthestringbeingcopied.
toggle
Thetoggleeventisgeneratedwhenshoworhidekeyboard,extendedkeyboardor
trackpad.
Parametersindata:
type:couldbe“KEYBOARD”,"EXTENDED_KEYPAD","TRACKPAD"
visibility:Boolean,truemean“show”,andfalsemeans“hide”.
SettingHandlersforWMKSEvents
InHTMLConsoleSDK,provideregister()andunregistermethodtoaddandremove
handlersforWMKSevents.
register()
ThismethodusedtoregistereventhandlerfortheWMKS.
Method
register
(eventName,eventHandler)
Parameter1 eventName( Constant, any value of WebMKS.Events)
Parameter2 eventHandler( javascript callback function)
Return Value None
Example Call var connectionStateHandler = function(event, data){};
wmks.register(WebMKS.Events.CONNECTION_STATE_CHANGE,
![](asset-c.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page12
connectionStateHandler);
unregister()
ThismethodisusedtounregistertheeventhandlerforWMKS.
Ifthismethodtakenoparameters,itwouldremovealltheeventhandlers.
If there is only one parameter, it would remove all the event handlers to that given
eventName.
Method
unregister
(eventName,eventHandler)
Parameter1 eventName(Constant,anyvalueofWebMKS.Events)
Parameter2 eventHandler( javascript callback function)
Return Value None
Example Call wmks.unregister(WebMKS.Events.CONNECTION_STATE_CHANGE,
connectionStateHandler);
MethodsoftheHTMLConsoleSDKObject
AfterinvokingthemethodcreateWMKS(),youwouldgetacoreWMKSobjectwhichcan
useWMKSAPItoconnecttoaVMandperformoperations.Inthis example, we will
nametheWMKSobject“wmks”.
GeneralAPIs
General‐purpose API methods provide information about WMKS. These methods can be
called at any time, including before you connect to target VM.
getVersion()
Retrieves the current version number of the HTMLConsoleSDK.
Method getVersion()
Parameters None
Return Value String. Contains the full version number of HTML Console SDK.
Example Call var version = wmks.getVersion();
getConnectionState()
Retrievesthecurrentconnectionstate.
Method getConnectionState()
Parameters None
Return Value Constant. Any value in WMKS. CONST.ConnectionState.
Example Call var state = wmks.getConnectionState();
![](asset-d.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page13
Lifecycle‐relatedAPIs
connect()
ConnectstheWMKStoaremotevirtualmachinebytheWebSocketURL,andsetsupthe
UI.
Method connect()
Paramete
r
WebSocket URL, type is string in format:
<ws | wss> :// <host:port>/ <path> /? <authentication info>
Return Value none
Example Call wmks.connect(“ws://localhost:8080”);
disconnect()
DisconnectsfromtheremotevirtualmachineandteardowntheUI.
Method disconnect()
Paramete
r
None
Return Value None
Example Call wmks.disconnect();
destroy()
Terminates the connection (if active) with the VM and removesthe widget from the
associatedelement.Consumersshouldcallthisbeforeremovingtheelementfromthe
DOM.
Method disconnect()
Paramete
r
None
Return Value None
Example Call wmks.destroy();
Display‐relatedAPIs
setRemoteScreenSize()
SendsarequesttosetthescreenresolutionofthecurrentlyconnectedVM.Here,ifthe
parameterswidthandheightthatarepassedarelargerthanthoseoftheWMKSwidget
allocatedsize,thesizingwouldbenormalized.
Note:this methodcouldworkproperlyonlywhentheoption changeResolutionsetto
true.
Method setRemoteScreenSize(width,height)
Paramete
r
1 width(int)represents the desired width of the connected vm, in pixel
Parameter2 height(int) represents the desired height of the connected vm, in pixel
Return Value None
Example Call wmks.setRemoteScreeSize(800,600);
![](asset-e.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page14
getRemoteScreenSize()
RetrievesthescreenwidthandheightinpixelsofcurrentlyconnectedVM.
Method getRemoteScreenSize()
Paramete
r
None
Return Value Object in format of {width:, height:}
Example Call var size = wmks.getRemoteScreenSize();
updateScreen()
Changes the resolution or rescale the remote screen to match the currently allocated
size.
The behavior of updateScreen depends on the option changeResolution, rescale, and
position:
1)IftheoptionchangeResolutionistrue,itwouldsendthechange resolution
requesttotheconnectedVM,therequestresolution(width&height)isthesame
asthecontainer'sallocatedsize.
2)Check rescale option: if true, rescale the remote screen tofitthecontainer's
allocatedsize.
3)Checkpositionoption:Iftheremotescreen'ssizeisnot the same as the
container'sallocatedsize,thentheremotescreenwillbeplacedinthecenteror
topleftofthecontainerbasedonitsvalue.
Method updateScreen()
Paramete
r
None
Return Value None
Example Call wvmrc.updateScreen();
Full‐screen‐relatedAPIs
canFullScreen()
Indicates if the fullscreen feature is enabled on this browser. Fullscreen mode is
disabled on Safari as it does not support keyboard input in fullscreen for security
reasons.
Method canFullScreen()
Paramete
r
None
Return Value Boolean. True mean can, false not.
Example Call wmks.canFullScreen();
![](asset-f.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page15
isFullScreen()
Informsifthebrowserisinfullscreenmode.
Method isFullScreen()
Paramete
r
None
Return Value Boolean. True mean in full screen mode, false not.
Example Call wmks.isFullScreen
()
;
enterFullScreen()
Forcesthebrowserenterfullscreenmodeifsupported.Inthefullscreenmode,onlythe
remotescreenwouldbedisplayed.
Method enterFullScreen()
Paramete
r
None
Return Value None
Example Call wmks.enterFullScreen();
exitFullScreen()
Forcesthebrowsertoexitfullscreenmode.
Method exitFullScreen()
Paramete
r
None
Return Value None
Example Call wmks.exitFullScreen();
Input‐relatedAPIs
sendInputString()
Sendsastringaskeyboardinputtotheserver.
Method sendInputString(string)
Parameters String
Return Value None.
Example Call wmks.sendInputString(“test”);
sendKeyCodes()
SendsaseriesofspecialkeycodestotheVM.Thistakesanarrayofspecialkeycodes
andsendskeydownsforeachintheorderlisted.Itthensendskeyupsforeachin
reverseorder.ThiscanbeusedtosendkeycombinationssuchasControl‐Alt‐Delete.
Method sendKeyCodes ()
Parameters Array. Each element in the array could be a keycode or a Unicode.
Keycode for none printable key, Unicode for printable character. If using
Unicode, negative it, such as -118 means “v”
![](asset-10.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page16
Return Value None.
Example Call wmks.sendKeyCodes([17,18,46]) ; // Ctrl + Alt + Delete
sendCAD()
SendsaControl‐Alt‐Deletekeysequencetothecurrentlyconnectedvirtualmachine.
Method sendCAD()
Parameters None.
Return Value None.
Example Call wmks.sendCAD();
Mobile‐relatedAPIs
enableInputDevice()
Enablestheinputdevice(keyboard,extendedkeyboard,trackpad)onthemobiledevice,
andinitialthemforuse.
Method enableInputDevice (deviceType)
Parameters deviceType:(Constant) Any value in WMKS.CONST.InputDeviceType.
Return Value None.
Example Call wmks.enableInputDevice(WMKS. CONST .InputDeviceType.
KEYBOARD) ;
disableInputDevice()
Disables the input device (keyboard,extendedkeyboard,trackpad) on the mobile
device,anddestroysthem.
Method disbleInputDevice (deviceType)
Parameters deviceType:(Constant) Any value in WMKS.CONST.InputDeviceType.
Return Value None.
Example Call wmks.disableInputDevice(WMKS. CONST .InputDeviceType.
KEYBOARD) ;
showKeyboard()
Showsthekeyboardonamobiledevice.
Method showKeyboard()
Parameters None
Return Value None.
Example Call wmks.showKeyboard();
hideKeyboard()
Hidesthekeyboardonamobiledevice.
![](asset-11.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page17
Method hideKeyboard()
Parameters None.
Return Value None.
Example Call wmks.hideKeyboard();
toggleExtendedKeypad()
Shows/hidestheextendedKeypadonthemobiledevicedependonthecurrentvisibility.
Method toggleExtendedKeypad()
Parameters A map, could include minToggleTime(ms) such as {minToggleTime: 50} if
the user try to call this toggle method too frequency, the duration less
then the minToggleTime, it would not been executed.
Return Value None.
Example Call wmks.toggleExtendedKeypad();
toggleTrackpad()
Shows/hidesthetrackpadonthemobiledevicedependonthecurrentvisibility.
Method toggleTrackpad()
Parameters A map, could include minToggleTime(ms) such as {minToggleTime: 50} if
the user try to call this toggle method too frequency, the duration less
then the minToggleTime, it would not been executed.
Return Value None.
Example Call wmks.toggleTrackpad();
toggleRelativePad()
Shows/hidestherelativemousetrackpadonthescreen.Willsendrelativemouseevent
insteadofabsolutemouseeventafteropenthisrelativepad.Canbeusedwhenthere’s
noVMwareToolsinstalledintheremoteguestOS.AddatoggleRelativeMousebuttonin
theUI,bindittotoggleRelativePad()API.Afterclickit,therelativetrackpadwilldisplay
and send relative mouse event to the remote guest. This is useful when the guest OS
doesn'tinstallVMwareToolsandcan'tacceptabsolutemouseevent.Becauseifthere's
nocursorimagecomesbackfromtheserver,weneedtodisplaylocalcursorpicture.So
wmks‐all.css under css folderand img folder are necessary to beaddintheproduct.
Theyareallunderwmkssdkfolder.
Method toggleRelativePad ()
Parameters A map, could include minToggleTime(ms) such as {minToggleTime: 50} if
the user try to call this toggle method too frequency, the duration less
then the minToggleTime, it would not been executed.
Return
V
alue None.
Example Call wmks.
toggleRelativePad ();
![](asset-12.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page18
Option‐relatedAPIs
setOption()
Changestheoptionvalue.Onlyoptionslistedbelowcanusethismethod:
rescale
position
changeResolution
useNativePixels
reverseScrollY
fixANSIEquivalentKeys
sendProperMouseWheelDeltas
keyboardLayoutId
Method
setOption
(optionName,optionValue)
Parameter1 optionName( string of the option name)
Parameter2 optionValue
Return Value None
Example Call wmks.setOption(“changeResolution”,false);
Appendix
ConstantsusedinWMKS
Position:WMKSwoulddisplaytheremotescreenofVMinequalproportion.
Thereforeafterrescale,theremotescreensizemaybestillnotthesamewiththe
container’ssize.HerePositionprovidestwopossibleoptionsforputthescreen
atwhichpositionofthecontainer.
ConnectionState:Thereare3possibleconnectionstateswhentryingto
connecttotheremoteVM.
Events:AlltheeventnamesthatWMKScantriggerarelistedhere.
ErrorType:possibleerrortypesinthelifecycleofWMKS.
InputDeviceType:HTMLConsoleSDKsupportsviewingVMconsolesonmobile
devices,andthisfieldliststhepossibleinputdevices.
(Pleaseseenextpageforlistofconstants)
![](asset-13.png)
Copyright©2009–2016VMware,Inc.Allrightsreserved.Copyrightandtrademarkinformation.
Page19
Position:{
CENTER:0,
LEFT_TOP:1
},
ConnectionState:{
CONNECTING:"connecting",
CONNECTED:"connected",
DISCONNECTED:"disconnected"
},
Events:{
CONNECTION_STATE_CHANGE:"connectionstatechange",
REMOTE_SCREEN_SIZE_CHANGE:"screensizechange",
FULL_SCREEN_CHANGE:"fullscreenchange",
ERROR:"error",
KEYBOARD_LEDS_CHANGE:"keyboardledschanged",
HEARTBEAT:"heartbeat",
AUDIO:"audio",
COPY:"copy",
TOGGLE:"toggle"
},
ErrorType:{
AUTHENTICATION_FAILED:"authenticationfailed",
WEBSOCKET_ERROR:"websocketerror",
PROTOCOL_ERROR:"protocolerror"
},
AudioEncodeType:{
VORBIS:"vorbis",
OPUS:"opus",
AAC:"aac"
},
InputDeviceType:{
KEYBOARD:0,
EXTENDED_KEYBOARD:1,
TRACKPAD:2
}