--===========================
local HoldKey= "space"
local ClearMouse= "Z"
--===========================
local ColorSticky= 0x00FF00FF --green
local ColorHeld= 0xFFFFFFFF --white
local ColorBoth= 0xFF0000FF --red; Sticky and held together is unpressed
--===========================
local btn={"left","up","right","down","A","B","X","Y","L","R","start","select",
"lid","debug"}
--*****************************************************************************
local function JoypadSet(inputs) -- Expects table containing keys
--*****************************************************************************
--I so wish FCEUX's "invert" option existed. This function mimics that.
--Best called from a function within emu.registerbefore
local JoyWanted= joypad.peek()
for i= 1, #btn do
if type(inputs[btn[i]]) == "string" then
inputs[btn[i]]= not JoyWanted[btn[i]]
end
end
joypad.set(inputs)
end
local held, sticky= {}, {}
--*****************************************************************************
local function MessWithInput()
--*****************************************************************************
--For use with emu.registerbefore
--Checks for held and stickied keys and applies them
local ThisInput= {}
for i= 1, #btn do
if sticky[btn[i]] then
ThisInput[btn[i]]= not held[btn[i]]
elseif held[btn[i]] then
ThisInput[btn[i]]= "inv"
end
end
JoypadSet(ThisInput)
if sticky.x then
stylus.set( {touch= true, x= sticky.x, y= sticky.y} )
elseif held.x then
if not stylus.peek().touch then
stylus.set( {touch= true, x= held.x , y= held.y } )
end
end
sticky= {}
end
emu.registerbefore(MessWithInput)
local fc= emu.framecount()
local LastButtons= joypad.peek()
--*****************************************************************************
local function PeekAtInput()
--*****************************************************************************
--For use with gui.register
--Peeks at input if the emulation is paused, and handles stuff.
--Doubles as display for the input it messes with.
local keys= input.get()
local _fc= emu.framecount()
if fc == _fc then
local buttons= joypad.peek()
for i= 1, #btn do
if buttons[btn[i]] and not LastButtons[btn[i]] then
if keys[HoldKey] then
held[btn[i]]= not held[btn[i]]
else
sticky[btn[i]]= not sticky[btn[i]]
end
end
end
LastButtons= buttons
buttons= stylus.peek()
if buttons.touch then
if keys[HoldKey] then
held.x= buttons.x
held.y= buttons.y
else
sticky.x= buttons.x
sticky.y= buttons.y
end
end
end
fc= _fc
if keys[ClearMouse] then
held.x= nil
held.y= nil
sticky.x= nil
sticky.y= nil
end
for i= 1, #btn do
local color
if sticky[btn[i]] then
if held[btn[i]] then
color= ColorBoth
else
color= ColorSticky
end
elseif held[btn[i]] then
color= ColorHeld
end
if color then
gui.text(1,10*i - 200, btn[i], color)
end
end
if held.x then
local color= 0xFFFFFFFF
if sticky.x then color= 0xFF0000FF end
gui.text(40,-185, held.x, color)
gui.text(60,-185, held.y, color)
end
if sticky.x then
gui.text(40,-170, sticky.x, 0x00FF00FF)
gui.text(60,-170, sticky.y, 0x00FF00FF)
end
end
gui.register(PeekAtInput)
This I call "sticky joypad". Save this into a .lua file and run it from DeSmuME's file menu, but if you needed me to tell you that, you probably need to learn a lot more about DeSmuME anyway.
Pause emulation, tap a button, and it will be pressed when you finally frame-advance. This should help in making sure you don't overload the keyboard trying to press so darn many buttons at once.
Also, hold space while pressing a joypad button, and it will act like the FCEUX-style auto-hold. This particular auto-hold can only be changed when emulation is paused, sorry about that.
And whether you like it or not, running this script will also stick or hold stylus input. A key is assigned to clear the stylus input (
how would one unclick the mouse effectively?), but change it to something other than
Z if you wish.
I sort of note a lack of a lua discussion thread, so I create my own topic to share my scripting stuff. Hope no one minds.