Task Manager Blocks Java Mouse Mover Program - java

I've quickly programmed a java program that randomly moves the cursor to prank my mate. Everything works perfectly except that when Task Manager is the current active window, the cursor doesn't move. It works fine when other applications are active. My questions are: What is causing this and if possible, how do i fix it. Here's my code(i know it's messy.):
Robot rob = new Robot();
while (true) {
PointerInfo pointer = MouseInfo.getPointerInfo();
Point point = pointer.getLocation();
int x = (int) point.getX();
int y = (int) point.getY();
int xd = getRandomDirection();
int yd = getRandomDirection();
rob.mouseMove(x+xd, y+yd);
}
private static int getRandomDirection() {
Random ran = new Random();
float ran1 = ran.nextFloat();
if(ran1 > 0.5){
return 1;
}else{
return -1;
}
}

I found the answer. Simply it is a rule in the newer versions of windows that a program that is not "run as admin" can't control over an admin-run program, e.g task manager. The simple solution was enabling the little checkbox on the program in windows with "rightclick" > "properties" > "Compatibility" > "Run as admin" or simply manually running as admin every time with a simple rightclick.

Related

Flickering Level Bar in Spigot/Minecraft Repeating Task

I'm currently running into a rather annoying problem.
Im running round about this task, with a Spigot-1.8 in Java 1.8. But this exact code gives me two diffrent Results.
In one the Levelbar of Minecraft just counts down and in another the Levelbar just flickers every time it sets the new XP Value.
private static int buildTask;
private static int buildSeconds = 120;
public static void buildingTime() {
buildTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(Plugin.getInstance(), () -> {
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
onlinePlayer.setLevel(buildSeconds);
}
//executing other Actions with Actionbar and Broadcasting Seconds to all players
if (buildSeconds <= 0) {
//ending here
}
buildSeconds--;
}, 0, 20);
}
I'm using this Spigot: https://getbukkit.org/get/hNiHm0tuqAg1Xg7w7zudk63uHr0xo48D
Already solved.... Let two tasks run at the same time which conflicted

Appium - Java, How to automate swipe in android?

Trying to automate android app using appium, when entered the below code for swipe giving ----
TouchAction io.appium.java_client.TouchAction.press(WebElement el)
#Deprecated
TouchAction ac = new TouchAction(driver);
ac.press(436,652).moveTo(-311,-14).release().perform();
What can be used to swipe?
The use of coordinates or wait times has been deprecated. You're now supposed to use ActionOptions. In the case of points, they're called PointOptions.
TouchAction works for me when giving it elements to start and stop the swiping at:
WebElement start = driver.findElement(By.id("xxxxxx"));
WebElement stop = driver.findElement(By.xpath("xxxxxx"));
TouchAction action = new TouchAction(driver);
action.longPress(start).moveTo(stop).release().perform();
The waitAction in the following code is crucial to properly implementing a swipe (that took me a couple hours of investigation to learn).
public static void actionSwipeLeft(AndroidDriver driver)
{
Dimension dims = driver.manage().window().getSize();
int x = (int) (dims.getWidth() * .5);
int y = (int) (dims.getHeight() * .8);
int endX = 0;
System.out.println("Swiping left.");
new TouchAction(driver)
.press(new PointOption().withCoordinates(x, y))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(500)))
.moveTo(new PointOption().withCoordinates(endX, y))
.release()
.perform();
}
I think one of commentors, Mike, might be right about wait times being deprecated. (The sources are all discombobulated.) This is the code that I use. Hope it helps.
new TouchAction(driver).longPress(PointOption.point(x, y)).moveTo(PointOption.point(x, y)).release().perform();

UnsatisfiedLinkError Libgdx Desktop

I am running into issues with LibGDX on Desktop. I keep getting the following error when trying to launch the application:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(I)Ljava/nio/ByteBuffer;
at com.badlogic.gdx.utils.BufferUtils.newDisposableByteBuffer(Native Method)
at com.badlogic.gdx.utils.BufferUtils.newUnsafeByteBuffer(BufferUtils.java:288)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:62)
at com.badlogic.gdx.graphics.glutils.VertexArray.<init>(VertexArray.java:53)
at com.badlogic.gdx.graphics.Mesh.<init>(Mesh.java:148)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:173)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:142)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:121)
at com.badlogic.gdx.graphics.g2d.SpriteBatch.<init>(SpriteBatch.java:115)
I have the following libraries added to my project:
gdx.jar
gdx-sources.jar
gdx-natives.jar
gdx-backend-lwjgl.jar
gdx-backend-lwjgl-natives.jar
Am I missing something?
I have searched high and low, but everything I find is for Android and tells me to add the .so libs from the arm folders to my project, but that doesn't make sense to me for a desktop project on wintel platform.
I'd advise you to setup your projects with this GUI. It should provide you with a valid setup for all platforms. You may also use the latest nightly builds and check if the problem still occurs. The problem might be that the native libraries do not match the other jars.
Another problem might be that you instantiate a SpriteBatch (or something else which internally uses a SpriteBatch) too early (looked a bit like this in the stacktrace). For example statically like this:
private static SpriteBatch batch = new SpriteBatch();
This won't work, since libgdx wasn't setup correctly at this point in time. Instead, create such things in the create/show methods of your game.
Use the following main method body to launch the object:
static public void main(String[] args) throws Exception {
// SkeletonViewer.args = args;
String os = System.getProperty("os.name");
float dpiScale = 1;
if (os.contains("Windows")) {
dpiScale = Toolkit.getDefaultToolkit().
getScreenResolution() / 96f;
}
if (os.contains("OS X")) {
Object object = Toolkit.getDefaultToolkit().getDesktopProperty(
"apple.awt.contentScaleFactor");
if (object instanceof Float && ((Float) object).intValue() >= 2) {
dpiScale = 2;
}
}
if (dpiScale >= 2.0f) {
uiScale = 2;
}
LwjglApplicationConfiguration.disableAudio = true;
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = (int) (800 * uiScale);
config.height = (int) (600 * uiScale);
config.title = "Skeleton Viewer";
config.allowSoftwareMode = true;
config.samples = 2;
new LwjglApplication(new SampleApplication(), config);
}

Barcode location while scanning

I'm using for my app the RedLaser library for barcode scanning (which is built off Zxing, I believe). Everything is working fine, while in scanning mode, any barcode that comes within view is scanned, but I don't want that, I want only barcodes that are aligned in a scanning area to be considered and the rest to be ignored.
The redlaser sample app, after which I implemented the library in my own app, had a rectangle on the layout of the scanning activiy, however that was ignored, as barcodes from any part of the screen were scanned and taken into account by the sample app.
Bottom line: I want my scanning activity to compare the location of the currently detected barcode and see if it is within the bounds of the "scanning area", if it is not then it won't be read.
Here is the code for the adjustment of the "scanning area":
viewfinderView = findViewById(R.id.view_finder);
LayoutParams params = new LayoutParams((int)(mDisplay.getWidth() * .75f),
(int)(mDisplay.getHeight() * .33f));
params.gravity = Gravity.CENTER;
viewfinderView.setLayoutParams(params);
The following code doesn't do anything, I just wrote it to exemplify the how everything works (since I don't have the source files for the Redlaser library), like the barcodelocation.
Set<BarcodeResult> allResults = (Set<BarcodeResult>) scanStatus.get(Status.STATUS_FOUND_BARCODES);
for( BarcodeResult s : allResults)
{
ArrayList<PointF> barcodelocation = s.barcodeLocation;
float x = barcodelocation.get(0).x;
float y = barcodelocation.get(0).y;
//there will be 4 points to each scanned barcode => 8 float's/barcode
}
Sorry for the long post, but I've been on this issue for a while now and I'm really stuck.
Any help is appreciated!
Managed to find a solution on the Redlaser site: turning the view into a rect then comparing the barcode location with that using .contain :
Rect scanningArea = new Rect(viewfinderView.getLeft(), viewfinderView.getTop(), viewfinderView.getRight(), viewfinderView.getBottom());
if(latestResult.iterator().hasNext())
{
boolean isInside = true;
ArrayList<PointF> barcodelocation = latestResult.iterator().next().barcodeLocation;
for (int i = 0; i < barcodelocation.size(); i++)
{
int x = (int) barcodelocation.get(i).x;
int y = (int) barcodelocation.get(i).y;
if (!scanningArea.contains(x, y))
{
isInside = false;
}
}
if (isInside)
{
//do stuff here
}
}
I'm still working on a few issues, but this question is answered now. Gonna go ahead and give myself a pat on the back. :)

ActionEvent in Java moves multiple buttons

Okay so I am pretty much doing a crash course through creating a java application and am having an issue with executing an action. The program is the 15 puzzle, the game where you slide one piece at a time and try to get all numbers in order, so I allow for an 'Auto' mode option that will solve the board for the user once clicked. So my code reads the solution from a text file which is working fine just none of the 'squares' (JButtons) move when I click the auto button. So i am not sure if I just don't understand the action even process completely or not. heres my code, I can supply more of it if necessary.
if (e.getSource() == ctrButtons[0]) {
System.out.println("Auto Mode started\n");
Scanner s = null;
try {
s = new Scanner(new BufferedReader(new FileReader("move_list.txt")));
int count = 0;
while (s.hasNext()) {
//Cycle through to move in move_list
if (count != 18) {
s.next();
count+=1;
}
else {
int cur_move = Integer.parseInt(s.next());
count = 0;
/*Use cur_move to move blank space accordingly
*UP------------3
*LEFT----------2
*RIGHT---------1
*DOWN----------0
*/
int zero_index = -1;
for (int j=0; j<jbnButtons.length; j++) {
if (Integer.parseInt(jbnButtons[j].getText()) == 0) {
zero_index = j;
break;
}
}
Point zero = jbnButtons[zero_index].getLocation();
//Check if move is up
if (cur_move == 3) {
Point next = jbnButtons[zero_index-4].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index-4].setLocation(zero);
}
//Check if move is left
else if (cur_move == 2) {
Point next = jbnButtons[zero_index-1].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index-1].setLocation(zero);
}
//Check if move is right
else if (cur_move == 1) {
Point next = jbnButtons[zero_index+1].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index+1].setLocation(zero);
}
//Check if move is down
else {
System.out.println("Current move = 0");
Point next = jbnButtons[zero_index+4].getLocation();
jbnButtons[zero_index].setLocation(next);
jbnButtons[zero_index+4].setLocation(zero);
}
}
}
}
So my code executes when I click the 'Auto' button and I was printing output to the screen to see if it was looping through the code which it was, just none of the buttons move each time through the loop. Any ideas??
You code is executing on the Event Dispatch Thread. The GUI can't repaint itself until the code finishes executing, so you won't see the intermediate steps only the final location of each component.
Read tje section from the Swing tutorial on Concurrency for a more complete explanation.
Maybe you should use a Swing Timer (the tutorial also has a section on this). Each time the Timer fire you do the next move.

Categories

Resources