issue with coding Left and right Shift Keys
in
Programming Questions
•
5 months ago
Hi, I am attempting to code a game in which two people use the keyboard to control characters on the screen, I am trying to code in a punch, and i wanted to know if there is a way to code the left shift key and the right shift key on the keyboard.
Heres Some of my code related to they key presses(if you need more code please let me know):
- //character 1----------------
- float movep1 = 10;
- float jump1 = 250;
- float jumps1 =.2;
- float gravity1 = -5;
- float speedp1 = 3;
- boolean a = false;
- boolean w = false;
- boolean d = false;
- boolean s = false;
- boolean Lshift = false;
- boolean space = false;
- //---------------------------
- //character2-----------------
- boolean up = false;
- boolean left = false;
- boolean down = false;
- boolean right = false;
- boolean Rshift = false;
- boolean Alt = false;
- /// KEY MOVE CODE
- void keyPressed() {
- println(keyCode);
- if (key == 'd' || key == 'D') {
- d = true;
- }
- if (key == 'a' || key == 'A') {
- a = true;
- }
- if (key == 'w' || key == 'W') {
- w = true;
- }
- if (key =='s' || key == 'S'){
- s = true;
- a=false;
- d = false;
- }
- if (key == 16){
- if (key == CODED) {
- if (keyCode == LEFT/*left*/) {
- left = true;
- }
- if (keyCode == UP/*up*/) {
- up = true;
- }
- if (keyCode == RIGHT/*right*/) {
- right = true;
- }
- }
- }
- void keyReleased() {
- if (key == 'd' || key == 'D') {
- d = false;
- }
- if (key == 'a' || key == 'A') {
- a = false;
- }
- if (key == CODED) {
- if (keyCode == LEFT/*left*/) {
- left = false;
- }
- if (keyCode == RIGHT/*right*/) {
- right = false;
- }
- }
- }
1