-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
78 lines (67 loc) · 1.68 KB
/
Copy pathmain.js
File metadata and controls
78 lines (67 loc) · 1.68 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
canvas = document.getElementById('myCanvas');
ctx = canvas.getContext("2d");
img_width = 300;
img_height = 100;
var img_image;
img_x = 100;
img_y = 100;
function add() {
img_imgTag = new Image(); //defining a variable with a new image
img_imgTag.onload = uploadimg; // setting a function, onloading this variable
img_imgTag.src = img_image; // load image
}
function uploadimg() {
ctx.drawImage(img_imgTag, img_x, img_y, img_width, img_height);
}
window.addEventListener("keydown", my_keydown);
function my_keydown(e)
{
keyPressed = e.keyCode;
console.log(keyPressed);
if((keyPressed >=97 && keyPressed<=122)|| (keyPressed >=65 && keyPressed<=90)){
aplhabetkey();
document.getElementById("d1").innerHTML = "You pressed alphabet key";
}else if (keyPressed >=48 && keyPressed <=57){
numberkey();
document.getElementById("d1").innerHTML = "You pressed number key";
}else if(keyPressed >= 37 && keyPressed <= 40){
arrowkey();
document.getElementById("d1").innerHTML = "You pressed arrow key";
}else if((keyPressed = 17) || (keyPressed = 18) || (keyPressed = 27)){
specialkey();
document.getElementById("d1").innerHTML = "You pressed a special key";
}else{
otherkey();
document.getElementById("d1").innerHTML="You pressed symbol or other key";
}
}
function aplhabetkey()
{
img_image="Alpkey.png";
console.log("Alphabet");
add();
}
function numberkey()
{
img_image="numkey.png";
console.log("Number");
add();
}
function arrowkey()
{
img_image="Arrkey.png";
console.log("Arrow");
add();
}
function specialkey()
{
img_image="spkey.png";
console.log("Special");
add();
}
function otherkey()
{
img_image="otherkey.png";
console.log("Other");
add();
}