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 Only When Pressed?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Wed Jan 19, 2022 12:47 pm    Post subject: Hotkey Only When Pressed? Reply with quote

I have already made a request for this, but was wondering how this can be done using lua or some other way:



Would like to be able to assign a hotkey value, only when the key/button is being pressed, else, it should revert back to 0 (or something else).

Also curious if this can be done as a quick-fix, without having to place something inside of the autorun folder, for example, within the table itself so that other people can make use of it without having to download any other files:

Code:
            <CheatEntry>
              <ID>82766</ID>
              <Description>"Move Higher"</Description>
              <ShowAsSigned>0</ShowAsSigned>
              <VariableType>Byte</VariableType>
              <Address>higher_input</Address>
              <Hotkeys>
                <Hotkey>
                  <Action>Set Value</Action>
                  <Keys>
                    <Key>22535</Key>
                  </Keys>
                  <Value>1</Value>
                  <ID>0</ID>
                </Hotkey>
              </Hotkeys>
            </CheatEntry>


Is this currently possible?

Thanks.
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Wed Jan 19, 2022 4:51 pm    Post subject: Reply with quote

I assume you haven't forgotten this post.

https://forum.cheatengine.org/viewtopic.php?t=602091

Do you have to do this on "Trainer Generator"?
It seems better to use Lua Script (CreateForm()) or UDF based Trainer.
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Wed Jan 19, 2022 5:02 pm    Post subject: Reply with quote

I am old. I forget things a lot.

Not making a trainer, just want the functionality for a table.

I just need a way to allow hotkeys to function only 'when pressed'.

For example, press and hold hotkey, value becomes 1. Once hotkey is released, value reverts back to 0.

The reason I want to set it up as a hotkey is because I want to be able to accommodate everyone, keyboards and controllers etc..

Thanks.
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Wed Jan 19, 2022 8:28 pm    Post subject: Reply with quote

You should check these posts:

https://forum.cheatengine.org/viewtopic.php?p=5734827
https://www.cheatengine.org/keypresstut.php

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Wed Jan 19, 2022 10:20 pm    Post subject: Reply with quote

Thanks. Unfortunately, those solutions will not work for me, assuming that I am understanding things correctly.

I see that it is likely possible, though. I am just not knowledgeable with lua to be able to write something.

I will keep researching and try to figure something out, nonetheless. Thanks for the help.
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Thu Jan 20, 2022 1:04 am    Post subject: Reply with quote

++METHOS wrote:
Thanks. Unfortunately, those solutions will not work for me, assuming that I am understanding things correctly.

I see that it is likely possible, though. I am just not knowledgeable with lua to be able to write something.

I will keep researching and try to figure something out, nonetheless. Thanks for the help.


It's to my understanding that you want functionality to assign a hotkey and once the script has activated, delete the hotkey?
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Thu Jan 20, 2022 4:42 am    Post subject: Reply with quote

++METHOS wrote:
Thanks. Unfortunately, those solutions will not work for me, assuming that I am understanding things correctly.

I see that it is likely possible, though. I am just not knowledgeable with lua to be able to write something.

I will keep researching and try to figure something out, nonetheless. Thanks for the help.


Master, I'm trying to understand you. I have a scenario in mind, I will collate @mgr.inz.Player's code and share a solution idea.

Please don't give up
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Thu Jan 20, 2022 4:54 am    Post subject: Reply with quote

I guess its need lua timer and isKeyPressed(key) function
Code:
--No timer included
if isKeyPressed(key) then
writeBytes(addr,1)
else --if not isKeyPressed
writeBytes(addr,0)
end

anothey way to use it is created function (bool write,true || false)
Code:
function writeBoolean(addr,bool)
    local result
    if addr == nil or bool == nil then
        return
    end
    result = bool and 1 or 0
    writeBytes(addr,result)
end

writeBoolean(addr,isKeyPressed(key)) --this line need to be in timer

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Thu Jan 20, 2022 11:54 am    Post subject: Reply with quote

LeFiXER wrote:
It's to my understanding that you want functionality to assign a hotkey and once the script has activated, delete the hotkey?
-Not exactly. I have a boolean type address that I want to be able to control so that the hotkey (that assigns the value to 1) will only function when the hotkey is actually being pressed down, and as soon as the player releases the key/button, the value reverts back to 0.

I was hoping to be able to do this, regardless of what key/button the player elects to assign as the hotkey, so I would need to be able to specify which symbol/address would be targeted, I suppose.

ByTransient wrote:
I have a scenario in mind, I will collate @mgr.inz.Player's code and share a solution idea.
-Thanks. I appreciate any help that I can get because my knowledge of lua is toilet.

Frouk wrote:
I guess its need lua timer and isKeyPressed(key) function
-Thank you very much. I will see if I can make sense of any of this and report back. Please bear with me because I am not very familiar with these things.

Thank you all for your help.

EDIT:
@Frouk - I have added this to the associated script, but I suspect that I am doing something wrong:
Code:

{$lua}
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
   if isKeyPressed(22535) then
      writeBytes(higher_input,1)
   else
      writeBytes(higher_input,0)
   end
end
{$asm}


I have tried many different variations of this as well as the other script that you posted to no avail.

Thanks.
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Thu Jan 20, 2022 5:32 pm    Post subject: Reply with quote

++METHOS wrote:

Not exactly. I have a boolean type address that I want to be able to control so that the hotkey (that assigns the value to 1) will only function when the hotkey is actually being pressed down, and as soon as the player releases the key/button, the value reverts back to 0.


++METHOS wrote:


Would like to be able to assign a hotkey value, only when the key/button is being pressed, else, it should revert back to 0 (or something else).


Why hold down the key (press(true(1)), press(false(0))) instead of pressing it 2 times? It's the same as constantly activating this code.

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

Just asking to rule out options.
Which is closer:

a) When I press the hotkey, I want to assign a hotkey to another script.
b) I want the address value to stay at "1" when I hold down the hotkey, and the address value to be "0" when I release the hotkey.
c) I want to activate the hotkey of another script when I press the hotkey.

d) Please write some hint steps too.

Note: Please do not give up. Smile
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Thu Jan 20, 2022 7:32 pm    Post subject: Reply with quote

b.

Thanks.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Fri Jan 21, 2022 1:04 am    Post subject: Reply with quote

I'm sure you find all keys here
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Fri Jan 21, 2022 3:21 am    Post subject: This post has 1 review(s) Reply with quote

Code:

[ENABLE]
{$lua}
_G._hotkeyTimer = createTimer();
_G._hotkeyTimer.Interval = 10;
_G._hotkeyTimer.OnTimer = function (t)
    if (isKeyPressed(22535)) then
        writeBytes('cheatengine-i386.exe', 1);
    else
        writeBytes('cheatengine-i386.exe', 0);
    end
end

{$asm}

[DISABLE]
{$lua}
if (_G._hotkeyTimer ~= nil) then
    _G._hotkeyTimer.destroy();
    _G._hotkeyTimer = nil;
end

{$asm}


Uses the right trigger button of an XInput gamepad to work.

If you only want to write the 0 when released once but still monitor, then you can add a previous state check like this:

Code:

[ENABLE]
{$lua}
_G._hotkeyTimer_PreviousState = false;
_G._hotkeyTimer = createTimer();
_G._hotkeyTimer.Interval = 10;
_G._hotkeyTimer.OnTimer = function (t)
    if (isKeyPressed(22535)) then
        writeBytes('cheatengine-i386.exe', 1);
        _G._hotkeyTimer_PreviousState = true;
    else
        if (_G._hotkeyTimer_PreviousState == true) then
            writeBytes('cheatengine-i386.exe', 0);
            _G._hotkeyTimer_PreviousState = false;
        end
    end
end

{$asm}

[DISABLE]
{$lua}
if (_G._hotkeyTimer ~= nil) then
    _G._hotkeyTimer.destroy();
    _G._hotkeyTimer = nil;
end

{$asm}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Fri Jan 21, 2022 6:10 am    Post subject: Reply with quote

++METHOS wrote:
b.


Here are some examples (Lua Script trials)
Code:
local indx=0

a1=keyDown(VK_P) and true or "true" or "false"
a2=keyUp(VK_I) and true or "true" or "false"
keyUp(VK_P)

function chTask()
--print("P pressed:  " .. a1 .. "\nI pressed:  " .. a2)
if a2=="true" then
print("P - stoped ! " .. indx)
keyUp(VK_P)
end
end

function chTask1()
indx=tonumber(indx) + 1
keyDown(VK_P)
if a1=="true" then
print("P - pressed ! " .. indx)
end
end

if pkey then pkey.Destroy() pkey=nil end
pkey=createHotkey(chTask, VK_P)

if pkey1 then pkey1.Destroy() pkey1=nil end
pkey1=createHotkey(chTask1, VK_I)


-------------------------------------------------
Code:
local indx=0
local indx1=1

function chTask()
indx=tonumber(indx) + 1
  print("P - Started ! " .. indx)

end

function chTask1()
sleep(20)
  if indx1==1 then
    indx1=2
     keyDown(VK_P)
     else
      keyUp(VK_P)
     print("P - stoped ! " .. indx)
    indx1=1
  end
end

if pkey then pkey.Destroy() pkey=nil end
pkey=createHotkey(chTask, VK_P)

if pkey1 then pkey1.Destroy() pkey1=nil end
pkey1=createHotkey(chTask1, VK_I)


The key never seems to stay pressed.
Cycle: pressed.. free.. pressed.. free..
It's just like simulating it being constantly pressed.
----------------------------------------------

Here's a different option: It just focuses on the value (Locks the value in the given constant) where you have to tap the key 2 times. It's a common scenario.

Code:
local indx1=1

function chTask1()
sleep(20)
local addresslist = getAddressList()
    addrCnt = addresslist[1].Description
    CheatEntry=addresslist.getMemoryRecordByDescription(addrCnt)
  if indx1==1 then
    if CheatEntry then
    CheatEntry.Value=1
    aa1=CheatEntry.Value
    CheatEntry.Active = true
    print(addrCnt .. ": " .. aa1)
    end
    indx1=2
     else
    if CheatEntry then
    CheatEntry.Value=0
    aa1=CheatEntry.Value
    CheatEntry.Active = false
    print(addrCnt .. ": " .. aa1)
    end
     print("stoped ! ")
    indx1=1
  end
end

if pkey1 then pkey1.Destroy() pkey1=nil end
pkey1=createHotkey(chTask1, VK_I)


-----------------------------------------------------
-----------------------------------------------------
The address list version would be:
(You can assign a key to it. )
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>2</ID>
      <Description>"Hack0"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end

sleep(20)
local addresslist = getAddressList()
    addrCnt = addresslist[1].Description
    CheatEntry=addresslist.getMemoryRecordByDescription(addrCnt)

    if CheatEntry then
    CheatEntry.Value=1
    aa1=CheatEntry.Value
    CheatEntry.Active = true
    print(addrCnt .. ": " .. aa1)
    end

{$asm}

[DISABLE]
{$lua}
local addresslist = getAddressList()
    addrCnt = addresslist[1].Description
    CheatEntry=addresslist.getMemoryRecordByDescription(addrCnt)
    if CheatEntry then
    CheatEntry.Value=0
    aa1=CheatEntry.Value
    CheatEntry.Active = false
    print(addrCnt .. ": " .. aa1)
    end
     print("stoped ! ")
</AssemblerScript>
      <Hotkeys>
        <Hotkey>
          <Action>Toggle Activation</Action>
          <Keys/>
          <Description>n</Description>
          <ID>0</ID>
        </Hotkey>
      </Hotkeys>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


Locked code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>3</ID>
      <Description>"No desc11"</Description>
      <LastState Value="1000" RealAddress="024BAE58"/>
      <VariableType>4 Bytes</VariableType>
      <Address>024BAE58</Address>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


... More ideas, more options. Wink
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Fri Jan 21, 2022 2:24 pm    Post subject: Reply with quote

atom0s wrote:
you can add a previous state check like this:
-Thank you. This works. This is not exactly what I was trying to accomplish, but this is much better than what I had.

That said, I wonder if it would be possible to have this work, regardless of what hotkey was assigned? Is this possible?

This is what I came up with to try to accommodate both, controller and keyboard players; although this works, it forces players to have to use specific buttons/keys:
Code:

{$lua}
_G._hotkeyTimer = createTimer();
_G._hotkeyTimer.Interval = 10;
_G._hotkeyTimer.OnTimer = function (t)
    if (isKeyPressed(22535)) or (isKeyPressed(38)) then
        writeBytes('higher_input', 1);
    else
        writeBytes('higher_input', 0);
    end
    if (isKeyPressed(22534)) or (isKeyPressed(40)) then
        writeBytes('lower_input', 1);
    else
        writeBytes('lower_input', 0);
    end
    if (isKeyPressed(22560)) or (isKeyPressed(87)) then
        writeBytes('north_input', 1);
    else
        writeBytes('north_input', 0);
    end
    if (isKeyPressed(22561)) or (isKeyPressed(83)) then
        writeBytes('south_input', 1);
    else
        writeBytes('south_input', 0);
    end
    if (isKeyPressed(22562)) or (isKeyPressed(68)) then
        writeBytes('east_input', 1);
    else
        writeBytes('east_input', 0);
    end
    if (isKeyPressed(22563)) or (isKeyPressed(65)) then
        writeBytes('west_input', 1);
    else
        writeBytes('west_input', 0);
    end
end

{$asm}


===========================================

Frouk wrote:
I'm sure you find all keys here
-Thanks. This was not the problem, but I appreciate you taking the time.

===========================================

ByTransient wrote:

The address list version would be:
(You can assign a key to it. )
Code:
<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>2</ID>
      <Description>"Hack0"</Description>
      <LastState/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
{$lua}
if syntaxcheck then return end

sleep(20)
local addresslist = getAddressList()
    addrCnt = addresslist[1].Description
    CheatEntry=addresslist.getMemoryRecordByDescription(addrCnt)

    if CheatEntry then
    CheatEntry.Value=1
    aa1=CheatEntry.Value
    CheatEntry.Active = true
    print(addrCnt .. ": " .. aa1)
    end

{$asm}

[DISABLE]
{$lua}
local addresslist = getAddressList()
    addrCnt = addresslist[1].Description
    CheatEntry=addresslist.getMemoryRecordByDescription(addrCnt)
    if CheatEntry then
    CheatEntry.Value=0
    aa1=CheatEntry.Value
    CheatEntry.Active = false
    print(addrCnt .. ": " .. aa1)
    end
     print("stoped ! ")
</AssemblerScript>
      <Hotkeys>
        <Hotkey>
          <Action>Toggle Activation</Action>
          <Keys/>
          <Description>n</Description>
          <ID>0</ID>
        </Hotkey>
      </Hotkeys>
    </CheatEntry>
  </CheatEntries>
</CheatTable>
-Thank you. This might be what I am looking for, but I am not sure how to go about setting this up. I will need to take some time to try to figure it out. I will report back after I have had some time to look at it.

Thank you all for your responses and for your help. I really appreciate it.

EDIT:
@ByTransient - I was not able to succeed with this script. Is there anything that I need to change, other this this line:

Code:
addrCnt = addresslist[1].Description


Also, It seems that rearranging the cheat entries in the table will create problems with this approach?

Thanks.
Back to top
View user's profile Send private message
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