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 Changer Help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Sat Nov 19, 2016 3:53 am    Post subject: Hotkey Changer Help Reply with quote

It's been a long while since I've been on here....I'm needing some help with lua

I wanna add a hotkey changer to my trainer

Example:
Drop down box which shows a list of hotkeys to choose from or a way for the user to pick it OWN hotkeys

_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Nov 19, 2016 7:40 am    Post subject: Reply with quote

You want to redefine keys of hotkey created with createHotkey() function?
Or redefine keys of hotkey attached to memory record?

_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Sat Nov 19, 2016 11:43 am    Post subject: Reply with quote

mgr.inz.Player wrote:
You want to redefine keys of hotkey created with createHotkey() function?
Or redefine keys of hotkey attached to memory record?

Could you show me both ways?

(Only if you want to)

_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sat Nov 19, 2016 12:25 pm    Post subject: Reply with quote

For example, if you have memory record with two hotkeys attached.

First one for enabling and second for disabling the cheat.

And you want to change to those: SHIFT+F2 and SHIFT+F3
you will do this:
Code:
local al = getAddressList()
local getMemRecByDesc = al.getMemoryRecordByDescription
local memrec = getMemRecByDesc('test')

memrec.Hotkey[0].Keys = {VK_SHIFT, VK_F2}
memrec.Hotkey[1].Keys = {VK_SHIFT, VK_F3}










For example, if you have hotkey created with createHotkey.
You just need to use setKeys method.

Code:
-- creating hotkey, SHIFT+F2
myHotkey = createHotkey(function () print'test' end, VK_SHIFT, VK_F2)

-- change to SHIFT+F3
myHotkey.setKeys(VK_SHIFT, VK_F3)





EDIT:

here script which adds small GUI:
Code:
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 = 120
  changeHotkeyKeysForm.Position = poScreenCenter
  changeHotkeyKeysForm.OnClose =
     function ()
       changeHotkeyKeysForm.CEEdit1.setFocus()
       return caHide
     end

  local CELabel1=createLabel(changeHotkeyKeysForm)
  CELabel1.Name = 'CELabel1'
  CELabel1.Left = 20
  CELabel1.Top = 20
  CELabel1.Caption = 'Set hotkey:'

  local CEEdit1=createEdit(changeHotkeyKeysForm)
  CEEdit1.Name = 'CEEdit1'
  CEEdit1.Text = ''
  CEEdit1.AnchorSideLeft.Control = CELabel1
  CEEdit1.AnchorSideTop.Control = CELabel1
  CEEdit1.AnchorSideTop.Side = asrBottom
  CEEdit1.Height = 25
  CEEdit1.Width = 248
  CEEdit1.BorderSpacing.Top = 4

  local clearButton=createButton(changeHotkeyKeysForm)
  clearButton.Name = 'clearButton'
  clearButton.AnchorSideLeft.Control = CEEdit1
  clearButton.AnchorSideTop.Control = CEEdit1
  clearButton.AnchorSideTop.Side = asrBottom
  clearButton.Height = 30
  clearButton.Width = 80
  clearButton.BorderSpacing.Top = 8
  clearButton.Caption = 'Clear'

  local applyButton=createButton(changeHotkeyKeysForm)
  applyButton.Name = 'applyButton'
  applyButton.AnchorSideLeft.Control = clearButton
  applyButton.AnchorSideLeft.Side = asrBottom
  applyButton.AnchorSideTop.Control = clearButton
  applyButton.Height = 30
  applyButton.Width = 80
  applyButton.BorderSpacing.Left = 10
  applyButton.Caption = 'Apply'

  CEEdit1.OnKeyDown = userPressedKey
  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])
    end

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

    changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)

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

  end

end







Usage:
Code:
changeHotkeyKeys(myHotkey)

changeHotkeyKeys(memrec.Hotkey[0])

_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Mon Nov 21, 2016 12:19 am    Post subject: Reply with quote

Thanks a lot man! I didn't know you was gonna write this script but I really appreciate you doing it!
_________________
Another Day, Another Hack.


Last edited by johnkittz on Tue Nov 22, 2016 6:31 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Nov 21, 2016 3:59 am    Post subject: Reply with quote

The great thing is: this simple script already works with controller input too.
_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Mon Nov 21, 2016 8:07 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
The great thing is: this simple script already works with controller input too.

that's awesome!

one more thing I'm having trouble with the script is it button activated? i cant seem to figure it out

_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 22, 2016 6:05 am    Post subject: Reply with quote

Usage:
Code:
changeHotkeyKeys(myHotkey)

changeHotkeyKeys(memrec.Hotkey[0])



You have to call changeHotkeyKeys function yourself.

_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Tue Nov 22, 2016 12:06 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
Usage:
Code:
changeHotkeyKeys(myHotkey)

changeHotkeyKeys(memrec.Hotkey[0])



You have to call changeHotkeyKeys function yourself.

(MyHotkey) is changed with an actual hotkey like VK_SHIFT?

I also get confused when people say "memrec Hotkey" (again probably another retarded thing to say)

(I'm learning lua slowly so this might be a retarded question just wanna learn everything I can about it)

_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 22, 2016 4:42 pm    Post subject: Reply with quote

Quote:
I also get confused when people say "memrec Hotkey"


here, hotkey attached to memory record (memory record can be: script, address, pointer, group/header):




PS: You designed trainer GUI from the scratch or you're using GUI created with "trainer generator"?

_________________


Last edited by mgr.inz.Player on Tue Nov 22, 2016 4:56 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Tue Nov 22, 2016 4:54 pm    Post subject: Reply with quote

Ahh okay it's just a hotkey assigned to a script lol I feel stupid now

I use trainer generator then design it manually

_________________
Another Day, Another Hack.


Last edited by johnkittz on Tue Nov 22, 2016 6:31 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 22, 2016 4:58 pm    Post subject: Reply with quote

So, you design it manually. Do you use CHEAT component (it is just visual component) or not?

PS: stop using quotes. We are still on the same page.

_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Tue Nov 22, 2016 5:48 pm    Post subject: Reply with quote

Yes I do and sorry I'm use to doing that on other forums
_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Tue Nov 22, 2016 6:11 pm    Post subject: Reply with quote

To keep this thread nice and tidy, you can still edit your older posts and remove quote blocks.

Anyway. Just updated my script.



You probably have few of those

Code:
function onPostHotkey0(Hotkey)
  --Executed after the "toggle*" cheat got executed
  local memrec=Hotkey.Owner
  local isActive=memrec.Active --get the state after the hotkey got triggered
  CETrainer.CHEAT0.setActive(isActive) --gui update, nothing else
  if gPlaySoundOnAction then
    if isActive then
      playSound(gActivateSound)
    else
      playSound(gDeactivateSound)
    end
  end
end

memrec0_hotkey0.onPostHotkey=onPostHotkey0


As you can see, CHEAT0 and memrec0_hotkey0 is a pair, connected together by above script.

User presses keys defined in memrec0_hotkey0, onPostHotkey0 function gets executed.
And that means CHEAT0 component gets signal to change text to Activationcolor (red) or back to normal text color (black). CHEAT0 component also has description field, hotkey field (it is just text).


collect those CHEAT{X} and memrec{Y}_hotkey{Z} pairs. And create lines like this:

addChangeHotkeyKeysFunctionality( CETrainer.CHEAT{X}, memrec{Y}_hotkey{Z} )



For example:
Code:
addChangeHotkeyKeysFunctionality(  CETrainer.CHEAT0, memrec0_hotkey0  )
addChangeHotkeyKeysFunctionality(  CETrainer.CHEAT1, memrec1_hotkey0  )



Add those lines at the end of Lua script.


Add this script at the very beginning:
Code:
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 = 120
  changeHotkeyKeysForm.Position = poScreenCenter
  changeHotkeyKeysForm.OnClose =
     function ()
       changeHotkeyKeysForm.CEEdit1.setFocus()
       return caHide
     end

  local CELabel1=createLabel(changeHotkeyKeysForm)
  CELabel1.Name = 'CELabel1'
  CELabel1.Left = 20
  CELabel1.Top = 20
  CELabel1.Caption = 'Set hotkey:'

  local CEEdit1=createEdit(changeHotkeyKeysForm)
  CEEdit1.Name = 'CEEdit1'
  CEEdit1.Text = ''
  CEEdit1.AnchorSideLeft.Control = CELabel1
  CEEdit1.AnchorSideTop.Control = CELabel1
  CEEdit1.AnchorSideTop.Side = asrBottom
  CEEdit1.Height = 25
  CEEdit1.Width = 248
  CEEdit1.BorderSpacing.Top = 4

  local clearButton=createButton(changeHotkeyKeysForm)
  clearButton.Name = 'clearButton'
  clearButton.AnchorSideLeft.Control = CEEdit1
  clearButton.AnchorSideTop.Control = CEEdit1
  clearButton.AnchorSideTop.Side = asrBottom
  clearButton.Height = 30
  clearButton.Width = 80
  clearButton.BorderSpacing.Top = 8
  clearButton.Caption = 'Clear'

  local applyButton=createButton(changeHotkeyKeysForm)
  applyButton.Name = 'applyButton'
  applyButton.AnchorSideLeft.Control = clearButton
  applyButton.AnchorSideLeft.Side = asrBottom
  applyButton.AnchorSideTop.Control = clearButton
  applyButton.Height = 30
  applyButton.Width = 80
  applyButton.BorderSpacing.Left = 10
  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])
    end

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

    changeHotkeyKeysForm.CEEdit1.Text=convertKeyComboToString(userDefinedKeys)

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

  end

end


function addChangeHotkeyKeysFunctionality(object1, object2)
  if (type(object1)=='userdata') and (object1.ClassName=='tcheat') and (object2.ClassName=='TMemoryRecordHotkey') then
    local btn = createButton(object1.Owner)
    btn.Parent = object1.Parent
    btn.AnchorSideLeft.Control = object1
    btn.AnchorSideTop.Control = object1
    btn.Height = object1.Height
    btn.Width = 15
    btn.BorderSpacing.Left = object1.Descriptionleft - 20
    btn.Caption = 'E'
    btn.OnClick = function () changeHotkeyKeys(object2) object1.Hotkey = object2.HotkeyString end
  end
end

_________________
Back to top
View user's profile Send private message MSN Messenger
johnkittz
Advanced Cheater
Reputation: 0

Joined: 17 May 2016
Posts: 95
Location: orderandhacks

PostPosted: Tue Nov 22, 2016 6:54 pm    Post subject: Reply with quote

I have the button showing just getting an error when pressed

error:
Error:[string "local function userPressedKey(sender, key)
..."]:128: attempt to index a nil value (global 'object2')

_________________
Another Day, Another Hack.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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