Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this code that basically reads if a key needs to be pressed in a game but im not sure how to make it

I have this code that basically reads if a key needs to be pressed in a game but im not sure how to make it into a exe file with a on and off button. can you make this code have and on and off button and upload the exe to a drop box and send me the link

import java.awt.KeyboardFocusManager;

import java.awt.event.KeyEvent;

/*IMPORTING VARIOUS MODULE FOR UTILITY FUNCTIONS*/

import java.awt.KeyEventDispatcher;

public class IsKeyPressed {

/*INTIALLY THE KEY PREES BOOLEAN IS TAKEN TO BE ALSE*/

private static volatile boolean wPressed = false;

public static boolean isWPressed() {/*USING SYNCHRONISATION CHECKING KEY PRESS*/

synchronized (IsKeyPressed.class) {/*RETURNNING BOOLEAN FOR KEY PRESS*/

return wPressed;

}

}

public static void main(String[] args) {

/*USING INBUILT FUNCTION FOR GETTING KEY EVENTS*/

KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher((KeyEvent ke) -> {

/*CHECKING KEY PRESS*/

synchronized (IsKeyPressed.class) {

switch (ke.getID()) {/*CHECKING IF KEY IS PRESSED*/

case KeyEvent.KEY_PRESSED:

/*IF KEY PRESSED GETTING ITS CODE*/

if (ke.getKeyCode() == KeyEvent.VK_W) {

wPressed = true;

}

break;

/*CHECKING IF KEY IS RELEASED*/

case KeyEvent.KEY_RELEASED:

if (ke.getKeyCode() == KeyEvent.VK_W) {/*KEY RELEASED EVENT IS FALSE*/

wPressed = false;

}

/*COMING OUT OF SWITCH*/

break;

}

return false;

}

} /*OVERIDING INHERITED CLASS FUNCTION*/ );

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

3. Discuss the process of behavior modeling training.

Answered: 1 week ago