Page 1 of 1

BUG in touch/mouse callbacks on Windows

Posted: Mon Jan 01, 2018 4:04 pm
by Silver Ankh
When touch is RELEASED two callbacks are triggered: love.touchreleased() and love.mousereleased() and it seems to be OK,but
when touch is PRESSED only love.touchpressed() is triggered, however love.mousepressed() is triggered when touch is moved or when touch is released (together with love.mousereleased()).
Try this simple program for better understanding.

Code: Select all

love.window.setFullscreen(true, "desktop")
local cMP, cMR, cTP, cTR = 0, 0, 0, 0
local cMPX, cMPY = 0, 0
local cMRX, cMRY = 0, 0
local cTPX, cTPY = 0, 0
local cTRX, cTRY = 0, 0
local xMP, xMR, xTP, xTR = "", "", "", ""

function love.mousepressed(x, y, button, isTouch)
    if x < 40 and y < 40 then
        love.event.quit()
    end
    cMP = cMP + 1
    xMP = "#" .. tostring(cMP) .. "." .. " X: " .. tostring(x) .. ", Y: " .. tostring(y)
    if isTouch then
        xMP = xMP .. " (Touch)"
    end
end

function love.mousereleased(x, y, button, isTouch)
    cMR = cMR + 1
    xMR = "#" .. tostring(cMR) .. "." .. " X: " .. tostring(x) .. ", Y: " .. tostring(y)
    if isTouch then
        xMR = xMR .. " (Touch)"
    end
end

function love.touchpressed(id, x, y, dx, dy, pressure)
    if x < 40 and y < 40 then
        love.event.quit()
    end
    cTP = cTP + 1
    xTP = "#" .. tostring(cTP) .. "." .. " X: " .. tostring(x) .. ", Y: " .. tostring(y)
end

function love.touchreleased(id, x, y, dx, dy, pressure)
    cTR = cTR + 1
    xTR = "#" .. tostring(cTR) .. "." .. " X: " .. tostring(x) .. ", Y: " .. tostring(y)
end

function love.update(dt)
end

function love.draw()
    love.graphics.setColor(1, 1, 1, 1)
    love.graphics.rectangle("fill", 0, 0, 40, 40)
    love.graphics.setColor(0, 0, 0, 1)
    love.graphics.print("QUIT", 5, 13)
    love.graphics.setColor(1, 1, 1, 1)
    love.graphics.print("Last .mousepressed()", 0, 50);   love.graphics.print(xMP, 160, 50)
    love.graphics.print("Last .mousereleased()", 0, 70);  love.graphics.print(xMR, 160, 70)
    love.graphics.print("Last .touchpressed()", 0, 90);   love.graphics.print(xTP, 160, 90)
    love.graphics.print("Last .touchreleased()", 0, 110); love.graphics.print(xTR, 160, 110)
end

Re: BUG in touch/mouse callbacks on Windows

Posted: Mon Jan 01, 2018 4:19 pm
by slime
love uses SDL for input, and SDL's touch/mouse event code on Windows uses Microsoft's Windows APIs pretty directly. This might be an issue with Windows or your touchscreen's drivers.

Re: BUG in touch/mouse callbacks on Windows

Posted: Mon Jan 01, 2018 4:50 pm
by davisdude
You can use the isTouch parameter for mousepressed/released to determine if it originated as a touch or click.

Re: BUG in touch/mouse callbacks on Windows

Posted: Mon Jan 01, 2018 4:58 pm
by Silver Ankh
slime wrote: Mon Jan 01, 2018 4:19 pm love uses SDL for input, and SDL's touch/mouse event code on Windows uses Microsoft's Windows APIs pretty directly. This might be an issue with Windows or your touchscreen's drivers.
OK, love.touchpressed() and love.touchreleased() working fine, I can use them for touch instead of mouse callbacks, no problem.
Thank you

Re: BUG in touch/mouse callbacks on Windows

Posted: Mon Jan 01, 2018 5:08 pm
by Silver Ankh
davisdude wrote: Mon Jan 01, 2018 4:50 pm You can use the isTouch parameter for mousepressed/released to determine if it originated as a touch or click.
You probably don't understand what I mean. I can't use isTouch parameter because love.mousepressed() is NOT triggered when I touch the screen. Is triggered in other, wrong moment.