Lua:textToShortCut

From Cheat Engine
Revision as of 19:48, 25 June 2026 by Leunsel (talk | contribs) (Major overhaul of the post.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

⚠️ Version Notice

This function requires Cheat Engine 6.4+.

<> Lua API Reference

function textToShortCut(shortcutstring) : integer

Converts a textual shortcut representation to a shortcut integer.

This function is available in Cheat Engine 6.4 and later.

Function Parameters

Parameter Type Description
shortcutstring String The textual shortcut representation to convert, such as "Ctrl+Alt+F1".

Returns

Integer — The shortcut integer represented by the given string.

Description

textToShortCut converts a human-readable shortcut string into the integer format used by Cheat Engine/Lazarus shortcut handling.

This is useful when shortcut values need to be stored as readable text and later applied to menu items, actions, or other objects that expect a shortcut integer.

Examples

Convert a shortcut string

1 local shortcut = textToShortCut("Ctrl+Alt+F1")
2 
3 print(shortcut)

Assign a shortcut to a menu item

1 local menuItem = createMenuItem(MainForm)
2 menuItem.Caption = "Custom Action"
3 menuItem.OnClick = function()
4   print("Custom action executed")
5 end
6 menuItem.ShortCut = textToShortCut("Ctrl+Shift+F5")

Store shortcuts as readable strings

1 local shortcuts = {
2   OpenMenu = "Ctrl+Alt+O",
3   RunAction = "Ctrl+Shift+R"
4 }
5 
6 local runShortcut = textToShortCut(shortcuts.RunAction)
7 
8 print(runShortcut)

Convert user input to a shortcut

1 local shortcutText = inputQuery("Shortcut", "Enter a shortcut:", "Ctrl+F1")
2 
3 if shortcutText ~= nil and shortcutText ~= "" then
4   local shortcut = textToShortCut(shortcutText)
5 
6   print("Shortcut integer: " .. tostring(shortcut))
7 end

Use a helper function

 1 local function applyShortcut(menuItem, shortcutText)
 2   if menuItem == nil or shortcutText == nil or shortcutText == "" then
 3     return false
 4   end
 5 
 6   menuItem.ShortCut = textToShortCut(shortcutText)
 7 
 8   return true
 9 end
10 
11 applyShortcut(MainForm.MenuItem2, "Ctrl+Alt+M")

Convert multiple shortcut strings

 1 local shortcutTexts = {
 2   "Ctrl+F1",
 3   "Ctrl+F2",
 4   "Ctrl+F3"
 5 }
 6 
 7 for i, shortcutText in ipairs(shortcutTexts) do
 8   local shortcut = textToShortCut(shortcutText)
 9 
10   print(shortcutText .. " = " .. tostring(shortcut))
11 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine