Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Keyboard to mouse movement for Android emulated games


  • Please log in to reply
7 replies to this topic
KuroFye
  • Members
  • 4 posts
  • Last active: Jul 03 2015 05:46 PM
  • Joined: 23 Jun 2015

Well i don't really know if this already exist around here but i didn't found it so i made a simple code to use with BlueStacks emulator that allows you to click-and-drag the mouse in the screen emulating the joystick movement you would do in an tablet with your thumbs using the WASD keys and some very simple clicks for other buttons. I know BlueStacks allows you to customize your own buttons too but it does not work well for me.

I made this code for my own screen resolution and for the game Marvel Future Fight and using the gamepad controller option, i left the code so anyone can customize where the "center of the joystick" will be in the X_axis and Y_axis, being those coordinates the center, and the offset is used as to how many pixels will the "joystick" move from the center (as a radius).

 

As the code uses keys used to write so i blocked the buttons so they will only start to respond once you press ctrl+Z and will stop responding if you press it again. I really don't know why but as long as the script is running the keyboard will not recognize W, A, S or D, so i added the ctrl+X command to close the app.

 

The other keys have to be customized, i just left the ones i use as an example, but i left a function that writes color and mouse position to a .txt in ctrl+F , you just need to change the location and name of the .txt for one you use, the script is at the bottom of the code. Also ctrl+A will reload the script to try changes fast.

 

If you get stuck in any directions just change directions and it will be ok, it is very far from perfect but it works, if anyone has a suggestion or wants to improve it'll be very welcome.

#NoEnv
#UseHook
SetBatchLines -1
active:= 1
attack_focus:=0
LocX:={Q:58,K:1123,I:1216,J:1292,E:69,R:1372,F:938,"J & I":1363,"J & K":1098}
LocY:={Q:312,K:657,I:550,J:734,E:457,R:364,F:802,"J & I":564,"J & K":796}

^!Z::active:= active ? 0 : 1
^!F::GetColor()
^!A::Reload
^!X::ExitApp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;   Keys
Q::    ; -Q change to second slot character
K::    ; -K first Skill
I::    ; -I second Skill
J::    ; -J regular attack
E::    ; -E change to third slot character
R::    ; -R friend Assist
F::    ; -F combined attack
J & I::    ; -combo third skill
J & K::    ; -combo fourth skill
if(active)
{
    attack_focus:=1
    send {LButton up}
    MouseMove, LocX[A_ThisHotkey] , LocY[A_ThisHotkey]
    Click
    attack_focus:=0
}
else
    send % strlen(A_ThisHotkey)=1 ? A_ThisHotkey : ""
Return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Movement
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

w::
a::
s::
d::
if(active)
    Move("w","a","s","d")
else
    Send % A_ThisHotkey
return

;;;;;;;;;;;;;;
;;; Others
;;;;;;;;;;;;;;

Move(Up,Left,Down,Right){
static D:=65, X:=0, Y:=0, Xc:=370, Yc:=675
BlockInput, MouseMove
        MouseMove, Xc , Yc
        send, {LButton Down}
        Loop{
                MouseMove, X := GetKeyState(Left,"P") ? Xc-D : GetKeyState(Right,"P") ? Xc+D : Xc
                                    , Y := GetKeyState(Up,"P") ? Yc-D : GetKeyState(Down,"P") ? Yc+D : Yc
                    Sleep 16
                }until ((X=Xc && Y=Yc) Or attack_focus) 
        send {LButton up}
BlockInput, MouseMoveOff
}

GetColor(){
    MouseGetPos, MouseX, MouseY
    PixelGetColor, color_get, MouseX, MouseY
    FileAppend, "The color at "%MouseX%" "%MouseY%" cursor position is "%color_get%`n, C:\_Bots\marvel_future_fight\datos.txt
}

EDIT: thanks a LOT to the user Xtra for helping with the code and my transition to the new version of AHK, made quite a lot of modifications but works much better now, keys have to be modified in the beginning of the code and edit their hotkey according. I now use my own computer hotkey to start the code and close it with ctrl+alt+X for fast change between windows. Any suggestion, question, request is welcome c:



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013
Spoiler


KuroFye
  • Members
  • 4 posts
  • Last active: Jul 03 2015 05:46 PM
  • Joined: 23 Jun 2015

it says this when i try to run it bro http://puu.sh/iBMXj/55fda4f9ab.png



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

You must be running an old version of AHK ;)



KuroFye
  • Members
  • 4 posts
  • Last active: Jul 03 2015 05:46 PM
  • Joined: 23 Jun 2015

oohhh i really learned a lot from this bro thanks a lot, would you mind taking a look at another script i have? 



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013

Sure PM me, use full editor mode and put it in code tags <>.

If there is any issues your having be thorough with the info.



KuroFye
  • Members
  • 4 posts
  • Last active: Jul 03 2015 05:46 PM
  • Joined: 23 Jun 2015

edited with the help from Xtra, thanks again bro!



LiNGo
  • Members
  • 1 posts
  • Last active: Dec 22 2015 08:10 AM
  • Joined: 21 Dec 2015

I'm new to autohotkey, so there's a lot I don't understand yet. Could you explain how the wasd movement part of the script works? Also, is the mouse color and position section of the script necessary for most games? If you need context, I'm trying to make this script work for World of Tanks Blitz.