Does anyone know how i center my mouse in the middle with python? - micropython

The problem I currently have is that the mouse pointer is in the middle bottom of my screen and I am not able to move it whatsoever. I need the mouse pointer in the middle of my screen so I can use it for cookie clicker.
Edit: i am making this auto clicker with my raspberry pi pico.
this is my code for an auto clicker for the Samsung Galaxy A70.
import time
import usb_hid
from adafruit_hid.mouse import Mouse
import board
import digitalio
MIDDLE_BUTTON = 4
RIGHT_BUTTON = 2
LEFT_BUTTON = 1
mouse = Mouse(usb_hid.devices)
led = digitalio.DigitalInOut(board.GP25)
led.direction = digitalio.Direction.OUTPUT
led.value = False
time.sleep(25)
mouse.move(y=360)
while True:
led.value = True
mouse.click(mouse.LEFT_BUTTON)
time.sleep(0.01)
Does anyone know how I can fix this?

Related

what does find_interface: error in godot vr mean?

I was following this tutorial https://docs.godotengine.org/en/3.1/tutorials/vr/vr_starter_tutorial.html
for vr in godot and the first few lines of code are (in func _ready())
var VR = ARVRServer.find_interface("OpenVR") ###
if VR and VR.initialize():
get_viewport().arvr = true
get_viewport().hdr = false
OS.vsync_enabled = false
Engine.target_fps = 90
when I run the code I get the error find_interface: Condition "idx == -1" is true. Returned: _null
The program runs, but the camera is static and moving the headset doesn't do anything. Doing vr stuff atm is probably out of my league but I just wanted to play around with it. please let me know if you have a solution, thanks! (also i am using a samsung odyssey plus)

Godot TouchScreen swipe detector

I'm making a simple android mobile game in Godot3.1. I would need to make a swipe detector that would determine if the player swiped and in which direction (left or right).
I tried this:
var swipe_start = null
var minimum_drag = 100
func _unhandled_input(event):
if event.is_action_pressed("click"):
swipe_start = event.get_position()
if event.is_action_released("click"):
_calculate_swipe(event.get_position())
func _calculate_swipe(swipe_end):
if swipe_start == null:
return
var swipe = swipe_end - swipe_start
if abs(swipe.x) > minimum_drag:
if swipe.x > 0:
_right()
else:
_left()
This works when you click with your mouse and swipe but it doesn't work when you play it on your android phone.
Any ideas?
That code only considers clicks and not screen touches, to correct that you have two options:
Go to Project > Project Settings > Input Devices > Pointing and turn on the Emulate Mouse From Touch option.
Or use the following code:
func _unhandled_input(event):
if event is InputEventScreenTouch:
if event.pressed:
swipe_start = event.get_position()
else:
_calculate_swipe(event.get_position())
instead of:
func _unhandled_input(event):
if event.is_action_pressed("click"):
swipe_start = event.get_position()
if event.is_action_released("click"):
_calculate_swipe(event.get_position())
With the last solution the code only accounts for screen touches so you wont be able to test it on PC unless you go to Project > Project Settings > Input Devices > Pointing and turn on the Emulate Touch From Mouse

Unity 2D Android - Restrict object to within the screen

I am working on a 2D Game similar to Space Shooter. I developed it for Web and PC and it works great. I am now porting it to Android and am having an issue with the Player code.
The player(a space ship) will be at the bottom of the screen and it moves left to right within the screen. I wrote a piece of code which limits the player within the screen and here is the code:
private float screenx = Screen.width -20;
playerPosScreen = Camera.main.WorldToScreenPoint(transform.position);
if(Input.GetKey(KeyCode.RightArrow) && playerPosScreen.x < screenx)
{
transform.Translate(Vector3.right * speed * Time.deltaTime * 0.4f);
}
if (Input.GetKey(KeyCode.LeftArrow) && playerPosScreen.x > 20)
{
transform.Translate(-Vector3.right * speed * Time.deltaTime * 0.4f);
}
I am aware that I still need to convert few of the static values in the above code and this is is not really a good way to code.
My question here is how do I do this in Android? I want the player to stay in the screen, i.e if the user moves the player by dragging him to extreme left, no matter how much ever he tries to drag, the player should stay at the left corner of the screen and the same applies to right. In simple terms I want to detect the left and right edges of the screen and limit my object within these edges.
My game will be in landscape mode.
Any help would be very much appreciated. Thanks in advance.
This sort of problem is generally solved in the following manor:
if(transform.position.x < screenx) {
transform.position.x = screenx;
}
Here, we are checking to see if the transformed player is out of the screen space. If it is, we set it to the minimum it can be - which I am assuming is screenx.
public Transform player;
public float distanceFromCamera=10;
public float offsetx=.05f;
public float offsety=.05f;
void Awake()
{
player.position=Camera.main.ViewportToWorldPoint(new Vector3(offsetx,offsety,distanceFromCamera));
}
this will be your bottom left screen boundry

How to create a Away3d Infinite tiling floor?

I am trying to create a scene with a infinite floor that seems to fade away in the distance in Away3d. I want the floor to have a texture. Prob is -- I can't seem to find any clear examples or tutorials that demonstrate this.
Ok you need to set your scene up, import local libs etc here we go
//Away3d
import away3d.containers.Scene3D;
import away3d.containers.View3D;
//etc
////////3D ModelScenes, Textures CLASS Exported 3DS/////////////////////
[Embed("assets/Images/grass1.jpg")]
var GrassTexture:Class;
var groundMaterial = new BitmapTexture(new GrassTexture().bitmapData);
////////GROUND MESH/////////////////////////////////////////////////////
var plane = new Mesh(new PlaneGeometry(3000,3000,30,30),new TextureMaterial(Cast.bitmapTexture(groundMaterial)));
plane.geometry.scaleUV(25, 25);
plane.material.repeat = true;
plane.material.alpha = 1;
container.addChild(plane);
Instead of tiling mesh/planes your better off having a really big plane and using the vertexes/polygons as tile locations...
Hope it helps

Flash to iPhone Very Slow Performance

I'm creating an iPhone app in Flash, and I've run into performance problems. I've stripped the entire thing down to a simple example (below). It draws a box to the screen, and uses TouchEvent to track finger gestures. Here's the problem: it is extremely sluggish on the iPhone 3G I am testing on. The box stutters up and down the page.
GPU mode is enabled in the application.xml, and when I set the -renderingdiagnostics flag, the text turns blue (meaning it is being rendered each time, which is correct), but the square stays white. It doesn't turn any of the three colors of diagnostics mode. Here is a screen of that:
http://whit.info/dev/flashapp/screen.jpg
And here is a video of the sluggishness:
http://vimeo.com/25160240
So, given that this is only one cached sprite moving vertically, am I missing something about enabling the GPU or bitmap caching? Or is this as good as it gets on this hardware? Other apps seem to glide brilliantly.
Can anyone assist?
Many thanks!
-Whit
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
[SWF(width='320', height='480', backgroundColor='#BACC00', frameRate='60')]
public class Main extends MovieClip{
private var square:Sprite;
private var txt:TextField;
private var startDragY:Number;
private var startObjY:Number;
public function Main(){
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
stage.addEventListener(TouchEvent.TOUCH_BEGIN, beginhandler);
stage.addEventListener(TouchEvent.TOUCH_MOVE, movehandler);
stage.addEventListener(TouchEvent.TOUCH_END, endhandler);
drawBox(0xffffff);
makeOutput();
}
private function beginhandler(evt:TouchEvent): void {
startDragY = evt.stageY;
startObjY = square.y;
}
private function movehandler(evt:TouchEvent): void {
out(String(evt.stageY));
square.y = startObjY - (startDragY - evt.stageY);
}
private function drawBox(fill:Number):void {
square = new Sprite();
square.graphics.beginFill(fill);
square.graphics.drawRect(20,60,40,40);
square.graphics.endFill();
stage.addChild(square);
square.cacheAsBitmap = true;
}
private function makeOutput():void {
txt = new TextField();
stage.addChild(txt);
txt.selectable = false;
txt.autoSize = TextFieldAutoSize.CENTER;
txt.defaultTextFormat = new TextFormat("Arial", 22, 0x000000);
txt.text = "Touch Screen";
txt.x = stage.stageWidth/2 - txt.width/2;
txt.y = stage.stageHeight/2 - txt.height/2;
}
private function out(str:String):void {
txt.text = str;
}
}
}
Also, here are the commands I'm using to compile:
.amxmlc ~/Files/Code/iOS/MyApp/Main.as
.pfi -package -renderingdiagnostics -target ipa-test -provisioning-profile MyApp.mobileprovision -storetype pkcs12 -keystore Certificates.p12 -storepass MyPass MyApp.ipa application.xml Main.swf Default.png icons
Latest Adobe updates are meant for the devices.
Our team was also facing the same problem and kinda solved the problem by updating the products.
We updated to:
Flash professional CS5.5
AIR 2.7
and the performance difference is noticeable.
Which version of the Flash exporter are you using? The CS5.5 update allegedly came with some speed boosts.
Also, the iPhone 3g on iOS 4 is already memory starved and I wouldn't be surprised if you were running out of memory with AIR loaded.
If you want good animation performance on an iPhone 3G (perhaps any iOS device), write your app in Objective C using Apple's provided Xcode tools. The result will run tons faster and eat up far less of your customer's device's battery and memory.