Jump to content

All my products and services are free. All my costs are met by donations I receive from my users. If you enjoy using any of my products, please donate to support me. My bare hosting costs are currently not met so please consider donating by either clicking this text or the Patreon link on the right.

Patreon

Recommended Posts

Posted

So I have this script that's been working ok for a while now to send arrow keys with mouse movements. I also have been using XPadder to send key presses. I even have an XPadder button combo that sends Escape when the right key combo is held. But, things don't quite want to work right.

I have the coin reject buttons set up for credit in MAME. I have it set up so that if you hold both coin buttons for 1 second, it quits (sends Escape). But, for some reason if you jam the coin buttons simultaneously, they ALWAYS exit. So I decided to write my own combo exit script in AutoHotKey. This works fine!

Anyway, I also wanted to change the buttons in GameEx so that I don't use CTL, ALT, or ENTER any more. These cause way too many potential problems with windows hotkeys. Here's were the snag is. I can use any buttons I want for buttons. I use the scancodes.txt and set custominputs.ini appropriately. I get my scripts updated and viola! The buttons work fine and no more combo problems! BUT, the arrow keys don't work. I've tried a bunch of things: send Up/Down, send scan code/virtual key of Up/Down, send SC/VK of </>, send SC/VK of a/s. The funny thing is that a/s work as select and back, but not as arrows.

What am I doing wrong? Or a better question: why does GameEx treat arrows differently than any other buttons? Maybe this has some kind of a conflict with the mouse? I'm not using v8.20 yet, so perhaps this would help. Any thoughts?

Here's the code. Feel free to use it if you want!

Mouse2Key.ahk

#InstallKeybdHook
#SingleInstance force

CoordMode, Mouse, Screen
SetKeyDelay, -1


SysGet, ScreenWidth, 78
SysGet, ScreenHeight, 79

x_center:=250 ;Starting x position
y_center:=250 ;Starting y position

SpeedThreshold:=200 ;Threshold speed where slow and fast scrolling is determined
DeadZone:=1 ;Minimum movement deadzone
CursorWatchSpeed:=25;How much delay between cursor position checks

NormalUp=VK26SC148;Up
NormalDown=VK28SC150;Down
FastUp=VK21SC149 ;Page Up
FastDown=VK22SC151 ;Page Down


#Persistent
SetTimer, WatchCursor, %CursorWatchSpeed%
return


WatchCursor:
IfWinActive GameEx|
{
MouseGetPos, xpos, ypos
DeltaX:=x_center-xpos
DeltaY:=y_center-ypos

;Only allow the most active axis to control GameEx menu
if abs(DeltaX)>abs(DeltaY)
{
DominantAxis:=X
Delta:=DeltaX
}
else
{
DominantAxis:=Y
Delta:=DeltaY
}

if (abs(Delta) < DeadZone)
{
;No Movement
}
else if (abs(Delta) < SpeedThreshold)
{
;Normal Movement
if (Delta<0)
{
if DominantAxis = X
{
SendInput {Blind}{%NormalUp% DownTemp}
SendInput {Blind}{%NormalUp% Up}
}
else
{
SendInput {Blind}{%NormalDown% DownTemp}
SendInput {Blind}{%NormalDown% Up}
}
}
else
{
if DominantAxis = X
{
SendInput {Blind}{%NormalDown% DownTemp}
SendInput {Blind}{%NormalDown% Up}
}
else
{
SendInput {Blind}{%NormalUp% DownTemp}
SendInput {Blind}{%NormalUp% Up}
}
}
}
else
{
;Fast Movement
if (Delta<0)
{
if DominantAxis = X
{
SendInput {Blind}{%FastUp% DownTemp}
SendInput {Blind}{%FastUp% Up}
}
else
{
SendInput {Blind}{%FastDown% DownTemp}
SendInput {Blind}{%FastDown% Up}
}
}
else
{
if DominantAxis = X
{
SendInput {Blind}{%FastDown% DownTemp}
SendInput {Blind}{%FastDown% Up}
}
else
{
SendInput {Blind}{%FastUp% DownTemp}
SendInput {Blind}{%FastUp% Up}
}
}
}

;Reinitialize mouse position for next step
DllCall("SetCursorPos", int, x_center, int, y_center)
}
return


#C::
{
ExitApp
}

JoystickRemappingScript.ahk

#InstallKeybdHook
#SingleInstance force

JoyButton1=VK41SC01E ;a
JoyButton2=VK53SC01F ;s
JoyButton3=VK44SC020 ;d
JoyButton4=VK46SC021 ;f




Joy1::
IfWinActive GameEx|
Send {Blind}{%JoyButton1% down} ; Hold down the left mouse button.
SetTimer, WaitForButtonUp1, 100
return

WaitForButtonUp1:
if GetKeyState("Joy1")
{
; Still down, so hit the button again
Send {Blind}{%JoyButton1% down}
SetTimer, WaitForButtonUp1, 30
Return
}
Else ; Otherwise, the button has been released.
{
Send {Blind}{%JoyButton1% up}
SetTimer, WaitForButtonUp1, off
Return
}



Joy2::
IfWinActive GameEx|
Send {Blind}{%JoyButton2% down} ; Hold down the left mouse button.
SetTimer, WaitForButtonUp2, 100
return

WaitForButtonUp2:
if GetKeyState("Joy2")
{
; Still down, so hit the button again
Send {Blind}{%JoyButton2% down}
SetTimer, WaitForButtonUp2, 30
Return
}
Else ; Otherwise, the button has been released.
{
; Otherwise, the button has been released.
Send {Blind}{%JoyButton2% up}
SetTimer, WaitForButtonUp2, off
Return
}



Joy3::
IfWinActive GameEx|
Send {Blind}{%JoyButton3% down} ; Hold down the left mouse button.
SetTimer, WaitForButtonUp3, 100
return

WaitForButtonUp3:
if GetKeyState("Joy3")
{
; Still down, so hit the button again
Send {Blind}{%JoyButton3% down}
SetTimer, WaitForButtonUp3, 30
Return
}
Else ; Otherwise, the button has been released.
{
; Otherwise, the button has been released.
Send {Blind}{%JoyButton3% up}
SetTimer, WaitForButtonUp3, off
Return
}



Joy4::
IfWinActive GameEx|
Send {Blind}{%JoyButton4% down} ; Hold down the left mouse button.
SetTimer, WaitForButtonUp4, 100
return

WaitForButtonUp4:
if GetKeyState("Joy4")
{
; Still down, so hit the button again
Send {Blind}{%JoyButton4% down}
SetTimer, WaitForButtonUp4, 30
Return
}
Else
{
; Otherwise, the button has been released.
Send {Blind}{%JoyButton4% up} ; Release the left mouse button.
SetTimer, WaitForButtonUp4, off
Return
}

Oh, and the button remapping script doesn't have the combo's included in this version.

Posted

This is really strange! I have GameEx set up with custom inputs on my main machine and it works fine. I use xpadder to send arrow keys and it works, but the script above doesn't. Very peculiar!

Posted
This is really strange! I have GameEx set up with custom inputs on my main machine and it works fine. I use xpadder to send arrow keys and it works, but the script above doesn't. Very peculiar!

Yeah, sorry not sure. Only shot in the dark would be check numlock.

I cant think for any reason that it would treat arrow keys any differently at the moment.

Posted

Hmmm. I have had it working with the default controls just fine, but I was getting strange things happening (like switching windows for some reason). I figured this was due to the ctl and alt keys in combo with the enter/1 and backspace.

What do you mean about numlock? The numlock needs to be on or off? I've never looked at that one.

Guest
This topic is now closed to further replies.
×
×
  • Create New...