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 


Cheat Engine Forum Index
PostGo back to topic
ByTransient
Expert Cheater
Reputation: 5
Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Feb 06, 2021 7:00 am    Post subject:

I tried to encode this with "InputQuery" for 8 hours.
I searched everywhere and could not find an example.
Again, I found the solution in your archive.
I'm waiting for a while for +1. I will return it after the deadline.
Thanks.
(I hope your score gets higher.)

An example for those who want to assign a user-defined hotkey in the trainer;

Code:
if f then f.Destroy() f=nil end
f = createForm(true)
f.Position = poDesktopCenter
f.Width = 220
f.Height = 160

l1=createLabel(f) l1.Left=70 l1.Top=60 l1.caption="key: "
l2=createCheckBox(f) l2.Left=70 l2.Top=20 l2.caption="hotkey change"
------------------------------------------------

local inputtext=([[
******************************************
******************************************
******  Set a hotkey or leave it blank (F8)  ******
******************************************
******************************************

or Click 'Apply']])

local function userPressedKey(sender, key)
  if userDefinedKeys[5]==0 then
    for i=1,5 do
      if userDefinedKeys[i]==0 then
        userDefinedKeys[i]=key
        break
      else
        if userDefinedKeys[i]==key then break end
      end
    end
  end

  changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)
  return 0
end

local function clearHotkey()
  userDefinedKeys={0,0,0,0,0}
  changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)
  changeHotkeyKeysForm.CEEdit1.setFocus()
end

local function formCreate()
  changeHotkeyKeysForm=createForm() --false)
  changeHotkeyKeysForm.Name = 'changeHotkeyKeysForm'
  changeHotkeyKeysForm.Caption = 'Hotkey Manually Set'
  changeHotkeyKeysForm.Width = 300
  changeHotkeyKeysForm.Height = 170
  changeHotkeyKeysForm.Position = poScreenCenter
  changeHotkeyKeysForm.OnClose =
     function ()
       changeHotkeyKeysForm.CEEdit1.setFocus()
       return caHide
     end

  local CELabel1=createLabel(changeHotkeyKeysForm)
  CELabel1.Name='CELabel1' CELabel1.Left=10
  CELabel1.Top=5 CELabel1.Caption=inputtext
  CELabel1.Alignment="taCenter"

  local CEEdit1=createEdit(changeHotkeyKeysForm)
  CEEdit1.Name='CEEdit1' CEEdit1.Text='F8'
  CEEdit1.Left=130 CEEdit1.Top=132
  CEEdit1.Height=30 CEEdit1.Width=40
  CEEdit1.Alignment="taCenter"

  local clearButton=createButton(changeHotkeyKeysForm)
  clearButton.Name='clearButton' clearButton.Left=10
  clearButton.Top=130 clearButton.Height=28
  clearButton.Width=100 clearButton.Caption='Clear'

  local applyButton=createButton(changeHotkeyKeysForm)
  applyButton.Name='applyButton' applyButton.Left=190
  applyButton.Top=130 applyButton.Height=28
  applyButton.Width=100 applyButton.Caption='Apply'

  CEEdit1.OnKeyDown = userPressedKey
  local mbtn={false,true,true,true}
  CEEdit1.OnMouseDown = function (s,k) if mbtn[k] then s.OnKeyDown(s,k+2) end end
  clearButton.OnClick = clearHotkey    -- clear button
  applyButton.ModalResult = mrYes      -- apply button
end

function changeHotkeyKeys(hotkey)
  if not changeHotkeyKeysFormCreated then
    changeHotkeyKeysFormCreated = true
    formCreate()
  end

  if hotkey==nil then return end

  userDefinedKeys={0,0,0,0,0}

  if hotkey.ClassName=='TGenericHotkey' then
    for i,v in ipairs({hotkey.getKeys()}) do
      userDefinedKeys[i]=v
    end

    changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)

    if changeHotkeyKeysForm.showModal()==mrYes then
      hotkey.setKeys(userDefinedKeys[1],userDefinedKeys[2],
                     userDefinedKeys[3],userDefinedKeys[4],
                     userDefinedKeys[5])
      print("hotkey3: "..changeHotkeyKeysForm.CEEdit1.Text)
      l1.caption="key: "..changeHotkeyKeysForm.CEEdit1.Text
    end

  elseif hotkey.ClassName=='TMemoryRecordHotkey' then
    for i,v in ipairs(hotkey.Keys) do
      userDefinedKeys[i]=v
    end
    object1.Hotkey = object2.HotkeyString

    changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)

    if changeHotkeyKeysForm.showModal()==mrYes then
      hotkey.Keys = userDefinedKeysh
    end
  end
end

----------------------------------------------------------------

function texter()
print("hotkey click")
end

if hk1 then hk1.destroy() hk1=nil end
hk1=createHotkey(texter, nil)

l2.OnChange=function(sender)
if sender.checked==true then
hk1=createHotkey(texter, nil)
--addChangeHotkeyKeysFunctionality(l1, hk1)
changeHotkeyKeys(hk1)
else
if hk1 then hk1.destroy() hk1=nil end
print("Key Close!")
end
end




Again Thanks .. (Y)

EDIT: That's 170 now. The target is 200, isn't there anybody who raised it?
Back to top
View user's profile Send private message
Post reviews:   Approve 1
Author Review
AylinCE
Review: Approve
Post reference:
ReviewPosted: Sun Feb 07, 2021 6:48 am

Thanks ..
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites