Eclipse SWT Shell : getBounds() seems to return false coordinates - swt

I tried the following to move the mouse pointer to the upper left corner of my shell (tested on Windows 10):
// get shell's coordinates
int x = shell.getBounds().x;
int y = shell.getBounds().y;
// move the cursor
Robot robot = new Robot();
robot.mouseMove(x, y);
But unfortunately this results in the placement of the mouse outside (left from and above the upper left corner) of the shell.
Any ideas?

Related

Getting angle between line and x-axis(horizontal top of screen)

I have created a basic program which draws shapes using graphics context. A line object holds its own start and end points. I wish to use the first quadrant values that are standard when building in java.
I have tried to create Point2D objects which gave me incorrect values. Also I have tried arctan2 and arctan which return the same value no matter which line I pass them. I cannot find my mistake whether it is my code or my math. Any suggestions will be appreciated.
double slope = (this.getEndY() - this.getyCoordinate()) / (this.getEndX() - this.getxCoordinate());
return MyLine.description + Math.toDegrees(Math.atan(slope));
this is using the Point2D with three points:
Point2D point = new Point2D(1, 0); // x- axis
Point2D point1 = new Point2D(this.getxCoordinate(),this.getyCoordinate()); //p1(0,0)
Point2D point2 = new Point2D(this.endX,this.getEndY());//p2(bottom right corner of window)
double angle = point1.angle(point, point2);
return MyLine.description + " " + angle;
The first attempt is the solution I found on the site already which returns NaN.
The second is an attemp to us the Point2d API which returns 0.0.
I am expecting it to read 45.0.

How i can't do swipe on tablet phone by katalon studio?

I can't find the correct "X" and "Y" coordinate. when I enter the "X" and "Y" coordinate it will scroll the top menu bar.now I am using tablet phone.
This might help for iOS swipe function
https://medium.com/#manishboricha308/ios-mobile-swipe-action-in-katalon-studio-4911199679e
For Android you can create another #Keyword custom
#Keyword
def swipeLeft(){
TouchAction touch = new TouchAction(getCurrentSessionMobileDriver())
int device_Height, device_Width
device_Height = Mobile.getDeviceHeight()
println device_Height
device_Width = Mobile.getDeviceWidth()
println device_Width
int midheight = device_Height/2
println midheight
int midwidth = device_Width/2
println midwidth
int startX,startY,endX,endY
startX = device_Width-100
startY = midheight
endX = -startX
endY = 0
Mobile.swipe(startX,startY,endX,endY)
touch.tap(startX, startY).perform()
}
When You SpyMobile Your device, and mark object You want to swipe or scroll on You will notice properties window filed.
There are X and Y also Height (H) and Width (W).
X and Y are absolute co-ordinates to the top left corner of the object.
H and W are the size of an object. So You do a simple calculation to see
co-ordinates for rest of corners of the object.
With this You know space You want to swipe or scroll on.
Hope it works for You.

Easeljs: Object added to stage on click has no X value

Trying to following the example at http://www.createjs.com/tutorials/Mouse%20Interaction/ , which shows how to drag and drop a shape. Something is going wrong for me. I add a circle when the stage is clicked, then I try to get it's x location... my alert shows a 0, but the circle appears in the right place. Then I try to drag, and the circle moves around, but at a distance from the mouse pointer.
var stage = new createjs.Stage("demoCanvas")
stage.on("stagemousedown", function(evt) {
var corn = new createjs.Shape()
corn.graphics.beginFill('white').drawCircle(evt.stageX, evt.stageY, 20).endFill()
stage.addChild(corn)
stage.update()
alert(corn.x)
corn.on("pressmove", function(dragEvent) {
dragEvent.target.x = dragEvent.stageX;
dragEvent.target.y = dragEvent.stageY;
stage.update()
});
})
You are mistaking the shape x/y position with the graphics coordinates. The shape is at [0,0], since you have not changed its x or y position.
Instead, draw the circle at [0,0], and move it to the mouse position.
var corn = new createjs.Shape()
.set({x:evt.stageX, y:evt.stageY});
corn.graphics.beginFill('green').drawCircle(0,0,20).endFill();
Here is a quick fiddle: http://jsfiddle.net/xnn803sx/

macOS - Move mouse by value

I have an app that receives data from an iOS app through bluetooth and it is supposed to move the mouse cursor.
The problem is that I get some weird functionality at y axis (x is fine).
The input looks like dx~dy where dx,dy are the values to move the cursor by. Here is an example:
-3.0~2.0
An example of my output:
Mouse loc: (596.0, 309.0) New Mouse loc: (603.0, 311.0)
Mouse loc: (603.0, 489.0) New Mouse loc: (610.0, 491.0)
Mouse loc: (610.0, 309.0) New Mouse loc: (615.0, 311.5)
Mouse loc: (615.0, 489.0) New Mouse loc: (618.0, 491.0)
Mouse loc: (618.0, 309.0) New Mouse loc: (618.5, 312.5)
As you can see first it has a lower y coordinate than a higher one. So basically the mouse keeps "jumping" up and down.
Here is my code that handles the input:
let mouseLoc = NSEvent.mouseLocation()
let newLoc = CGPoint(x: mouseLoc.x-CGFloat(x), y: mouseLoc.y+CGFloat(y))
CGDisplayMoveCursorToPoint(0, newLoc)
EDIT: in the test case I had values between 0 and 2 so there is no way to have a difference of 100 between two states
Cocoa and Core Graphics (a.k.a. Quartz) use different coordinate systems. In Cocoa, the origin is at the lower left of the primary screen and y increases as you go up. In Core Graphics, the origin is at the top left of the primary screen and y increases as you go down.
Since you're using a Core Graphics function to move the cursor, you need to convert from Cocoa's coordinate system.
var mouseLoc = NSEvent.mouseLocation()
mouseLoc.y = NSHeight(NSScreen.screens()![0].frame) - mouseLoc.y;
// etc.

How can I get my sprite to move up and down the screen in FANG? Right now it's just moving back and forth across the screen

Right now it's just bouncing back and forth across the screen
def moveTriangleTwo {
triTwo.translateX(triTwoDX)
if (triTwo.getX < 0.0) {
// It hit the left wall - go other direction
triTwo.setX(0.0) // Place it on left wall
triTwoDX = -triTwoDX // Move in opposite direction
} else if (triTwo.getX > -1) {
// It hit the right wall - go other direction
triTwo.setX(-1.0) // Place it on right wall
triTwoDX = -triTwoDX // Move in opposite directinectin
}
}
Perhaps you should read about vectors and coordinate systems.
The short answer is, on a computer screen, coordinate Y is the vertical axis, starting with 0 on top. The X coordinate is horizontal, starting at 0 on the left and increasing to the right.
For horizontal movement you need to change X, for vertical you change Y, for any diagonal you change both at once.