diff --git a/Lua API.html b/Lua API.html index f14239a10..aa41b8b63 100644 --- a/Lua API.html +++ b/Lua API.html @@ -1749,7 +1749,10 @@ options; if multiple interpretations exist, the table will contain multiple keys

Maps to an integer in range 0-255. Duplicates a separate "STRING_A???" code for convenience.

_MOUSE_L, _MOUSE_R
-

If the left or right mouse button is pressed.

+

If the left or right mouse button is being pressed.

+
+
_MOUSE_L_DOWN, _MOUSE_R_DOWN
+

If the left or right mouse button was just pressed.

If this method is omitted, the screen is dismissed on receival of the LEAVESCREEN key.

diff --git a/Lua API.rst b/Lua API.rst index cedc36441..eaef74997 100644 --- a/Lua API.rst +++ b/Lua API.rst @@ -1610,7 +1610,10 @@ Supported callbacks and fields are: Maps to an integer in range 0-255. Duplicates a separate "STRING_A???" code for convenience. ``_MOUSE_L, _MOUSE_R`` - If the left or right mouse button is pressed. + If the left or right mouse button is being pressed. + + ``_MOUSE_L_DOWN, _MOUSE_R_DOWN`` + If the left or right mouse button was just pressed. If this method is omitted, the screen is dismissed on receival of the ``LEAVESCREEN`` key. diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 99bf9263c..603c7ab44 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -13,6 +13,8 @@ CLEAR_PEN = to_pen{ch=32,fg=0,bg=0} local FAKE_INPUT_KEYS = { _MOUSE_L = true, _MOUSE_R = true, + _MOUSE_L_DOWN = true, + _MOUSE_R_DOWN = true, _STRING = true, } diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index cd20bc25e..782bb317d 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -664,14 +664,24 @@ int dfhack_lua_viewscreen::do_input(lua_State *L) if (enabler && enabler->tracking_on) { - if (enabler->mouse_lbut) { + if (enabler->mouse_lbut_down) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_L"); } - if (enabler->mouse_rbut) { + if (enabler->mouse_rbut_down) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_R"); } + if (enabler->mouse_lbut) { + lua_pushboolean(L, true); + lua_setfield(L, -2, "_MOUSE_L_DOWN"); + enabler->mouse_lbut = 0; + } + if (enabler->mouse_rbut) { + lua_pushboolean(L, true); + lua_setfield(L, -2, "_MOUSE_R_DOWN"); + enabler->mouse_rbut = 0; + } } lua_call(L, 2, 0);