Skip to content

How to get subtitle word under mouse via lua scripting? #15907

Answered by guidocella
BLumia asked this question in Q&A
Discussion options

You must be logged in to vote

There's no way to get the position of words in the subtitle. At best you can use a script like this to select a word in a menu. You need git master for mouse support.

local input = require 'mp.input'

mp.add_key_binding('F1', 'select-sub-word', function ()
    local words = {}
    for word in mp.get_property('sub-text', ''):gmatch('%g+') do
        words[#words + 1] = word
    end

    if #words == 0 then
        return
    end

    input.select({
        prompt = 'Select a word:',
        items = words,
        submit = function (i)
            mp.osd_message('Selected ' .. words[i])
            -- Do something with the word.
        end
    })
end)

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@BLumia
Comment options

@guidocella
Comment options

@BLumia
Comment options

Answer selected by BLumia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants