Created
December 16, 2013 18:18
-
-
Save BenWoodford/7991692 to your computer and use it in GitHub Desktop.
Fixed reference to #js-steam-input, the id wasn't set on the element.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Remote Control</title> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css"> | |
<style> | |
.container { | |
width: 700px; | |
} | |
.alert { | |
margin-top: 20px; | |
} | |
.page-header { | |
margin-top: 0; | |
} | |
.row { | |
margin-bottom: 15px; | |
} | |
.mousetrap { | |
margin-bottom: 0; | |
-webkit-user-select: none; | |
-moz-user-select: none; | |
user-select: none; | |
} | |
.mousetrap h3 { | |
text-align: center; | |
color: #CCC; | |
} | |
.list-group { | |
margin-top: 15px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="alert fade"> | |
<p>Error</p> | |
</div> | |
<div class="page-header"> | |
<h1>Steam Remote Control</h1> | |
</div> | |
<div class="input-group"> | |
<input class="form-control input-lg js-steam-input" id="js-steam-input" type="text"> | |
<div class="input-group-btn"> | |
<button class="btn btn-default btn-lg js-steam-sequence">Sequence</button> | |
<button class="btn btn-default btn-lg js-steam-key">Key</button> | |
<button class="btn btn-default btn-lg js-steam-button">Button</button> | |
<button class="btn btn-default btn-lg js-steam-games">Run Game</button> | |
</div> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="btn-group btn-group-justified"> | |
<a class="btn btn-lg btn-info js-steam-button" data-button="left"><span class="glyphicon glyphicon-arrow-left"></span></a> | |
<a class="btn btn-lg btn-info js-steam-button" data-button="right"><span class="glyphicon glyphicon-arrow-right"></span></a> | |
<a class="btn btn-lg btn-info js-steam-button" data-button="up"><span class="glyphicon glyphicon-arrow-up"></span></a> | |
<a class="btn btn-lg btn-info js-steam-button" data-button="down"><span class="glyphicon glyphicon-arrow-down"></span></a> | |
<a class="btn btn-lg btn-success js-steam-button" data-button="a">A</a> | |
<a class="btn btn-lg btn-danger js-steam-button" data-button="b">B</a> | |
<a class="btn btn-lg btn-primary js-steam-button" data-button="x">X</a> | |
<a class="btn btn-lg btn-warning js-steam-button" data-button="y">Y</a> | |
</div> | |
</div> | |
<div class="row"> | |
<div class="well mousetrap"> | |
<h3>It's a trap</h3> | |
</div> | |
</div> | |
<div class="row"> | |
<a class="btn btn-lg btn-default btn-block" id="btn-get-list"><span class="glyphicon glyphicon-list"></span> Get games</a> | |
<div class="list-group" id="list-index"></div> | |
</div> | |
</div> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> | |
<script id="sillyfunctions"> | |
var trapArea = $( '.well' ), input = $( '#js-steam-input' ), last_position = { x: 0.0, y: 0.0 }; | |
// Key trap | |
$( document ).on( 'keydown', function( e ) | |
{ | |
if( trapArea.is( ':hover' ) ) | |
{ | |
e.preventDefault(); | |
var key = 'key_' + Keycode.GetValueByEvent( e ); | |
trapArea.find( 'h3' ).text( key ); | |
SteamRemoteClient.Keyboard.Key( key ); | |
} | |
} ); | |
$( document ).on( 'mousemove', function( e ) | |
{ | |
if( trapArea.is( ':hover' ) ) | |
{ | |
var deltaX = last_position.x - event.clientX, | |
deltaY = last_position.y - event.clientY; | |
last_position = | |
{ | |
x: event.clientX, | |
y: event.clientY | |
}; | |
jQuery.ajax( { | |
url: SteamRemoteClient.Address + 'mouse/move', | |
data: | |
{ | |
device_name: SteamRemoteClient.DeviceName, | |
device_token: SteamRemoteClient.DeviceToken, | |
delta_x: deltaX, | |
delta_y: deltaY | |
}, | |
method: 'POST', | |
dataType: 'json', | |
timeout: 5000 | |
} ); | |
} | |
} ); | |
// TODO: No idea if this is working | |
$( trapArea ).on( 'click', function( e ) | |
{ | |
jQuery.ajax( { | |
url: SteamRemoteClient.Address + 'mouse/click/left/', | |
data: | |
{ | |
device_name: SteamRemoteClient.DeviceName, | |
device_token: SteamRemoteClient.DeviceToken | |
// button: 'button_left' | |
}, | |
method: 'POST', | |
dataType: 'json', | |
timeout: 5000 | |
} ); | |
} ); | |
// Get list | |
$( '#btn-get-list' ).click( function( e ) | |
{ | |
e.preventDefault( ); | |
SteamRemoteClient.Games.Index( function( data ) | |
{ | |
$( '#list-index' ).empty( ); | |
console.log( data ); | |
for( var i in data.data ) | |
{ | |
var link = $( '<a></a>', { class: 'list-group-item', href: '#', 'data-appid': i } ); | |
var game = data.data[ i ]; | |
var name = game.name; | |
if( game.installed ) | |
{ | |
name = '<b>' + name + '</b>'; | |
} | |
else | |
{ | |
name = '<i>' + name + ' (' + ( 0 | game.estimated_disk_bytes / 1000000 ) + ' MB)</i>'; | |
} | |
link.html( name ).click( function( e ) | |
{ | |
e.preventDefault( ); | |
$( '#steamquence' ).val( $( this ).data( 'appid' ) ); | |
} ); | |
$( '#list-index' ).append( link ); | |
} | |
if( $( '#list-index' ).is( ':empty' ) ) | |
{ | |
$( '#list-index' ).append( $( '<span></span>', { class: 'list-group-item' } ).text( 'The list is empty :(' ) ); | |
} | |
} ); | |
} ); | |
$( '.js-steam-sequence' ).on( 'click', function( e ) | |
{ | |
e.preventDefault(); | |
SteamRemoteClient.Keyboard.Sequence( input.val() ); | |
} ); | |
$( '.js-steam-key' ).on( 'click', function( e ) | |
{ | |
e.preventDefault(); | |
SteamRemoteClient.Keyboard.Key( input.val() ); | |
} ); | |
$( '.js-steam-button' ).on( 'click', function( e ) | |
{ | |
e.preventDefault(); | |
SteamRemoteClient.Button.Press( $( this ).data( 'button' ) || input.val() ); | |
} ); | |
$( '.js-steam-games' ).on( 'click', function( e ) | |
{ | |
e.preventDefault(); | |
SteamRemoteClient.Games.Action( input.val(), 'run' ); | |
} ); | |
</script> | |
<script id="remoteui"> | |
var SteamRemoteClient = | |
{ | |
Address: location.protocol + '//' + location.host + '/steam/', | |
DeviceName: 'SteamDB Hacks', | |
DeviceToken: 'AmazingSteamDB', | |
AlertTimeout: 0, | |
Keyboard: | |
{ | |
Sequence: function( sequence ) | |
{ | |
SteamRemoteClient.DoPOST( 'keyboard/sequence/', 'sequence', sequence ); | |
}, | |
Key: function( name ) | |
{ | |
SteamRemoteClient.DoPOST( 'keyboard/key/', 'name', name ); | |
} | |
}, | |
Button: | |
{ | |
Press: function( button ) | |
{ | |
SteamRemoteClient.DoPOST( 'button/' + button + '/' ); | |
} | |
}, | |
Games: | |
{ | |
Index: function( callback ) | |
{ | |
jQuery.ajax( { | |
url: SteamRemoteClient.Address + 'games/', | |
data: | |
{ | |
device_name: SteamRemoteClient.DeviceName, | |
device_token: SteamRemoteClient.DeviceToken | |
}, | |
success: callback, | |
dataType: 'json', | |
timeout: 5000 | |
} ); | |
}, | |
Action: function( appid, action ) | |
{ | |
SteamRemoteClient.DoPOST( 'games/' + appid + '/' + action + '/' ); | |
} | |
}, | |
DoPOST: function( url, paramName, paramValue ) | |
{ | |
var data = | |
{ | |
device_name: SteamRemoteClient.DeviceName, | |
device_token: SteamRemoteClient.DeviceToken | |
}; | |
if( paramName && paramValue ) | |
{ | |
data[ paramName ] = paramValue; | |
} | |
jQuery.ajax( { | |
url: SteamRemoteClient.Address + url, | |
data: data, | |
method: 'POST', | |
dataType: 'json', | |
timeout: 5000, | |
success: function( ) | |
{ | |
$( '.alert' ).removeClass( 'alert-danger' ).addClass( 'alert-success in' ).find( 'p' ).html( '<b>Request Executed:</b> /' + url + ' {' + paramName + ': ' + paramValue + '}' ); | |
clearInterval( SteamRemoteClient.AlertTimeout ); | |
SteamRemoteClient.AlertTimeout = setTimeout( function( ) | |
{ | |
$( '.alert' ).removeClass( 'in' ); | |
}, 2500 ); | |
}, | |
error: function( ) | |
{ | |
$( '.alert' ).removeClass( 'alert-success' ).addClass( 'alert-danger in' ).find( 'p' ).html( '<b>Request Failed:</b> /' + url + ' {' + paramName + ': ' + paramValue + '}' ); | |
clearInterval( SteamRemoteClient.AlertTimeout ); | |
SteamRemoteClient.AlertTimeout = setTimeout( function( ) | |
{ | |
$( '.alert' ).removeClass( 'in' ); | |
}, 2500 ); | |
} | |
} ); | |
} | |
}; | |
</script> | |
<script id="keymap"> | |
var Keycode = | |
{ | |
GetKeyCodeValue: function( keyCode, shiftKey ) | |
{ | |
if( shiftKey === true ) | |
{ | |
return this.ModifiedByShift[ keyCode ]; | |
} | |
return this.KeyCodeMap[ keyCode ]; | |
}, | |
GetValueByEvent: function( e ) | |
{ | |
return this.GetKeyCodeValue( e.which, e.shiftKey ); | |
}, | |
KeyCodeMap: | |
{ | |
8:"backspace", 9:"tab", 13:"enter", 16:"shift", 17:"ctrl", 18:"alt", 19:"pausebreak", 20:"capslock", 27:"escape", 32:"space", 33:"pageup", | |
34:"pagedown", 35:"end", 36:"home", 37:"left", 38:"up", 39:"right", 40:"down", 43:"+", 44:"printscreen", 45:"insert", 46:"delete", | |
48:"0", 49:"1", 50:"2", 51:"3", 52:"4", 53:"5", 54:"6", 55:"7", 56:"8", 57:"9", 59:";", | |
61:"=", 65:"a", 66:"b", 67:"c", 68:"d", 69:"e", 70:"f", 71:"g", 72:"h", 73:"i", 74:"j", 75:"k", 76:"l", | |
77:"m", 78:"n", 79:"o", 80:"p", 81:"q", 82:"r", 83:"s", 84:"t", 85:"u", 86:"v", 87:"w", 88:"x", 89:"y", 90:"z", | |
96:"0", 97:"1", 98:"2", 99:"3", 100:"4", 101:"5", 102:"6", 103:"7", 104:"8", 105:"9", | |
106: "*", 107:"+", 109:"-", 110:".", 111: "/", | |
112:"f1", 113:"f2", 114:"f3", 115:"f4", 116:"f5", 117:"f6", 118:"f7", 119:"f8", 120:"f9", 121:"f10", 122:"f11", 123:"f12", | |
144:"numlock", 145:"scrolllock", 186:";", 187:"=", 188:",", 189:"-", 190:".", 191:"/", 192:"`", 219:"[", 220:"\\", 221:"]", 222:"'" | |
}, | |
ModifiedByShift: | |
{ | |
192:"~", 48:")", 49:"!", 50:"@", 51:"#", 52:"$", 53:"%", 54:"^", 55:"&", 56:"*", 57:"(", 109:"_", 61:"+", | |
219:"{", 221:"}", 220:"|", 59:":", 222:"\"", 188:"<", 189:">", 191:"?", | |
96:"insert", 97:"end", 98:"down", 99:"pagedown", 100:"left", 102:"right", 103:"home", 104:"up", 105:"pageup" | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment