Is there a way to change certain attributes of a shape onscreen when a specific key is pressed by the user? For example, can I make it so that pressing "a" changes the color of the shape?
I attempted to modify a mouse rollover event to work with the desired key press input.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<link rel="stylesheet" href="css/screen.css">
<style>
.box1{
background:#1E90FF;
width: 1000px;
height:100px;
float:right;
margin: 0px 0px 0px 0px;
}
.circle {
height: 200px;
width: 200px;
background-color: #1E90FF;
border-radius: 50%;
}
.toprectangle {
height: 80px;
width: 200px;
background-color: #1E90FF;
float:right;
margin: 0px 40px 20px 80px;
border: 1px solid #1E90FF;
}
.square {
height: 80px;
width: 200px;
background-color: #1E90FF;
float:right;
margin: 10px 40px 10px 1000px;
border: 1px solid #1E90FF;
<!--Third square down-->
}
.box2{
background:#1E90FF;
width: 1400px;
height:100px;
float:right;
margin: 60px 0px 0px 0px;
<!--rectangle at the bottom-->
}
.box3{
background:#1E90FF;
width: 200px;
height:600px;
margin: 0px 20px 130px 0px;
<!--rectangle going up the side-->
}
.circle1{
height: 200px;
width: 200px;
background-color: #1E90FF;
border-radius: 50%;
margin: 10px 500px 0px;
}
</style>
</head>
<body>
<script>
function onkeypress(evt);
if(onkeypress == 49):
.toprectangle {
height: 80px;
width: 200px;
background-color: #ff78ff;
float:right;
margin: 0px 40px 20px 80px;
border: 1px solid #1E90FF;
}
</script>
<div class="box1"></div>
</div>
<div class="circle"></div>
<div class="circle1"></div>
<div class="toprectangle"></div>
<div class="square"></div>
<div class="square"></div>
<div class="box3"></div>
<div class="box2"></div>
<svg width="500" height="150">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page Title</title>
<link rel="stylesheet" href="css/screen.css">
<style>
</style>
</head>
<body>
.toprectangle {
height: 80px;
width: 200px;
background-color: #1E90FF;
float:right;
margin: 0px 40px 20px 80px;
border: 1px solid #1E90FF;
}
<script>
function onkeypress(evt);
if(onkeypress == 49):
.toprectangle {
height: 80px;
width: 200px;
background-color: #ff78ff;
float:right;
margin: 0px 40px 20px 80px;
border: 1px solid #1E90FF;
}
</script>
<div class="box1"></div>
</div>
<div class="circle"></div>
<div class="circle1"></div>
<div class="toprectangle"></div>
<div class="square"></div>
<div class="square"></div>
<div class="box3"></div>
<div class="box2"></div>
</body>
</html>
The goal is to have different shapes change colors based on the user's key presses, but currently, the code does not respond to any inputs.