-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyflex.js
61 lines (51 loc) · 1.17 KB
/
keyflex.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var context = new AudioContext()
var o = null
var g = null
var keycmd = ""
document.addEventListener('DOMContentLoaded', function(){
$(".js_play_sound").on("mousedown", function(e){
e.preventDefault()
var $target = $(e.target)
eval($target.data("source"))
})
$(".js_play_sound").on("mouseup", function(e){
e.preventDefault()
o.stop()
keyup()
})
$(".js_stop_sound").on("click", function(e){
e.preventDefault()
//o.stop()
//keyup()
})
}, false)
function example1(){
context.resume()
o = context.createOscillator()
o.type = "sine"
o.connect(context.destination)
o.start()
keydown()
}
function keydown(){
keycmd = "http://192.168.4.1/light/on?msg=D"
keysend()
}
function keyup(){
keycmd = "http://192.168.4.1/light/on?msg=U"
keysend()
}
function keysend(){
if (typeof XMLHttpRequest != "undefined") {
req = new XMLHttpRequest()
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP")
}
req.open("GET", keycmd, true)
//req.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
req.onreadystatechange = sk_cb
req.send(null);
}
function sk_cb(){
return
}