Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Hotkey for Form -> Edit?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 208

PostPosted: Fri Feb 27, 2026 6:33 am    Post subject: Hotkey for Form -> Edit? Reply with quote

Is it possible to create hotkey "F11" for UDF1 -> Edit? To be able to open the form designer using a hotkey.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1554

PostPosted: Fri Feb 27, 2026 1:15 pm    Post subject: Reply with quote

Think carefully before putting this into Autorun:
Will the form name always be "UDF1"?
And will there only be 1 form?

I'm leaving a code here as a starting point for improvement.


Code:
function clickMenuByPath(path)
    local current = MainForm.Menu.Items
    for part in path:gmatch("[^>]+") do
        local found = false
        for i = 0, current.Count - 1 do
            if current[i].Caption:gsub("&", "") == part then
                current = current[i]
                found = true
                break
            end
        end
        if not found then return false end
    end
    current.doClick()
    return true
end

--clickMenuByPath("Table>UDF1>Edit")

if opnUdf1Key then opnUdf1Key.Destroy() opnUdf1Key=nil end
if opnUdf2Key then opnUdf2Key.Destroy() opnUdf2Key=nil end

opnUdf1Key = createHotkey(function() clickMenuByPath("Table>UDF1>Edit") end, VK_F11)
opnUdf2Key = createHotkey(function() clickMenuByPath("Table>UDF2>Restore and show") end, VK_F12)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dark Byte
Site Admin
Reputation: 472

Joined: 09 May 2003
Posts: 25880
Location: The netherlands

PostPosted: Fri Feb 27, 2026 3:06 pm    Post subject: Reply with quote

Yup.
Also, just one tiny little contribution :

change the path to:
Code:

translate('Table')..'>UDF1>'..translate('Edit')

so that people that use translation files can also use it

(and instead of a hotkey, a menuitem with a shortcut might suffice as well)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 208

PostPosted: Fri Feb 27, 2026 4:51 pm    Post subject: Reply with quote

AylinCE wrote:
Think carefully before putting this into Autorun:
Will the form name always be "UDF1"?

Yes, usually it is UDF1.
The code works. But if I open a ".CT" file with a UDF1 form, then hotkey will not work until I click on the "Table" menu. How to fix this? It will be much better if we can use a hotkey without clicking on the "Table" menu.

Dark Byte wrote:

(and instead of a hotkey, a menuitem with a shortcut might suffice as well)

Yes, menuitem with a shortcut would be much better. Can you also show an example?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1554

PostPosted: Fri Feb 27, 2026 9:29 pm    Post subject: Reply with quote

Try this.

But the shortcut key isn't "F11".
This allows you to grab multiple forms and arrange them with keys ranging from "Ctrl+1" to 9 to open their edits.
It cancels the shortcut key of the deleted form and refreshes the entire form list with keys.

For those who design multiple forms, it determines the keys at startup (with Autorun) and aligns them from bottom to top with Ctrl+1, 2, 3...

Code:
-- Global table to manage hotkey objects
if udfHotkeys == nil then udfHotkeys = {} end

-- Function to destroy existing hotkeys to prevent duplicates
function clearOldUDFHotkeys()
    for _, hk in ipairs(udfHotkeys) do
        if hk and hk.destroy then hk.destroy() end
    end
    udfHotkeys = {}
end

function refreshUDFShortcuts()
    -- Ensure the Main Form and Table Menu are fully loaded
    if not (MainForm and MainForm.miTable) then return end

    clearOldUDFHotkeys()

    local miTable = MainForm.miTable
    local formCounter = 1

    -- Scanning components under the "Table" menu
    for i = 0, miTable.ComponentCount - 1 do
        local menuObj = miTable.Component[i]

        -- Filter: UDF forms typically have an empty Name property but a valid Caption
        if menuObj and menuObj.Caption ~= nil and (menuObj.Name == "" or menuObj.Name == nil) then

            -- sub-menu index [1] is 'Edit' and index [3] is 'Delete'
            local editMenu = menuObj[1]
            local deleteMenu = menuObj[3]

            if editMenu and editMenu.Caption:gsub("&", "") == translate("Edit") then
                if formCounter <= 9 then
                    local currentCounter = formCounter -- Closure capture

                    -- 1. Try to set the visual Shortcut (standard CE behavior)
                    -- We use pcall to prevent errors if the property is temporarily locked
                    --pcall(function()
                        editMenu.Shortcut = textToShortCut("Ctrl+"..currentCounter)
                    --end)

                    -- 2. Create the robust Global Hotkey as a fallback/primary trigger
                    local hk = createHotkey(function()
                        if editMenu and editMenu.doClick then
                            editMenu.doClick()
                            --print("Editor triggered for: " .. menuObj.Caption)
                        end
                    end, tonumber(VK_1) + (currentCounter - 1), VK_CONTROL)

                    table.insert(udfHotkeys, hk)

                    -- 3. Hook the Delete button to refresh list when a form is removed
                    if deleteMenu and deleteMenu.Caption:gsub("&", "") == translate("Delete") then
                        if deleteMenu.Tag ~= 1337 then -- Prevent double hooking
                            local oldDel = deleteMenu.OnClick
                            deleteMenu.OnClick = function(sender)
                                if oldDel then oldDel(sender) end
                                -- Delay refresh to allow CE to remove the menu item first
                                local t = createTimer()
                                t.Interval = 500
                                t.OnTimer = function(tm)
                                    tm.destroy()
                                    refreshUDFShortcuts()
                                end
                                t.Enabled=true
                            end
                            deleteMenu.Tag = 1337
                        end
                    end

                    formCounter = formCounter + 1
                end
            end
        end
    end
end

-- Hook into the "Create Form" button in the Table menu
local miCreate = MainForm.miCreateLuaForm
if miCreate then
    local oldCreate = miCreate.OnClick
    miCreate.OnClick = function(sender)
        if oldCreate then oldCreate(sender) end
        -- Wait for the new form to be registered in the menu
        local t = createTimer()
        t.Interval = 1000
        t.OnTimer = function(tm)
            tm.destroy()
            refreshUDFShortcuts()
        end
        t.Enabled=true
    end
end

-- INITIALIZATION:
-- We use a small delay on startup to ensure all CT forms are loaded before scanning
local initTimer = createTimer()
initTimer.Interval = 500
initTimer.OnTimer = function(tm)
    tm.destroy()
    refreshUDFShortcuts()
end

initTimer.Enabled=true


If you're using a UDF1 or single form for the first form, you can give it its own custom key and make the others standard.

In the main code, replace the following section with:

Code:
                    -- 2. Create the robust Global Hotkey as a fallback/primary trigger
                    local hk = createHotkey(function()
                        if editMenu and editMenu.doClick then
                            editMenu.doClick()
                            --print("Editor triggered for: " .. menuObj.Caption)
                        end
                    end, tonumber(VK_1) + (currentCounter - 1), VK_CONTROL)

                    table.insert(udfHotkeys, hk)


replace:
Code:
                -- 2. Create the robust Global Hotkey as a fallback/primary trigger
                local hk
                if i==0 then
                    hk = createHotkey(function()
                        if editMenu and editMenu.doClick then
                            editMenu.doClick()
                            --print("Editor triggered for: " .. menuObj.Caption)
                        end
                    end, VK_F11)
                else
                    local hk = createHotkey(function()
                        if editMenu and editMenu.doClick then
                            editMenu.doClick()
                            --print("Editor triggered for: " .. menuObj.Caption)
                        end
                    end, tonumber(VK_1) + (currentCounter - 1), VK_CONTROL)
                end
                table.insert(udfHotkeys, hk)


How can we assign a shortcut (Shortcut()) to the current menu item (Edit)? @DarkByte could probably provide an example.
Code:
editMenu.Shortcut = textToShortCut("Ctrl+"..currentCounter)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Razi
Expert Cheater
Reputation: 1

Joined: 17 Jan 2018
Posts: 208

PostPosted: Sat Feb 28, 2026 9:09 am    Post subject: Reply with quote

AylinCE wrote:
Try this.
replace:

The hotkey works if "Create form" was clicked. If the ".CT" file was opened with the UDF1 form that was created earlier, then the hotkey does not work.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1554

PostPosted: Sat Feb 28, 2026 10:27 am    Post subject: Reply with quote

My mistake.

I set the timer value too short during CE's initial startup, waiting for it to fully load.

Give CE some time to load (it might be more than 3 seconds) and then allow the code to run.

Code:
-- INITIALIZATION:
-- We use a small delay on startup to ensure all CT forms are loaded before scanning
local initTimer = createTimer()
initTimer.Interval = 500


-- use
Code:
initTimer.Interval = 500*7

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dark Byte
Site Admin
Reputation: 472

Joined: 09 May 2003
Posts: 25880
Location: The netherlands

PostPosted: Sat Feb 28, 2026 11:21 am    Post subject: Reply with quote

in your shortcut handler first do
Code:

MainForm.miTable.doClick()

so the menuitems gets created

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites