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 


Sending Key Press
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Fri Feb 11, 2022 5:45 pm    Post subject: Sending Key Press Reply with quote

I have this code:

Code:
newmem_auto_block:
  cmp byte ptr [rcx+08],#24
  jg block
  jmp originalcode_auto_block

block:
{$lua}
  doKeyPress(69)
  doKeyPress(22531)
{$asm}
jmp originalcode_auto_block


It does not seem to be working. Do I need to do something else for this to work?

If it turns out that repeating the KeyPress is needed, how would I go about doing that? Just copy/paste it multiple times?

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

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Fri Feb 11, 2022 6:18 pm    Post subject: This post has 1 review(s) Reply with quote

Instead of imagining pressing the key,
It is better to give the keypress.
Of course, you specify the pressure removal interval.

Code:
keyDown(69)
  keyDown(22531)
sleep(50)
keyUp(69)
keyUp (22531)

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Fri Feb 11, 2022 6:33 pm    Post subject: Reply with quote

Thank you for your help, AylinCE. I really appreciate it.

It seems that the keys are still not getting sent. I am not sure why.

EDIT: I can see that the keys are being sent when I execute the script, but I need them to execute inside of my assembly script once the proper conditions are met after the compare. They keys are not getting pressed once the code jumps to this area in the game.

Thanks.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4300

PostPosted: Fri Feb 11, 2022 6:53 pm    Post subject: Reply with quote

{$lua} blocks are executed when the script is enabled/disabled. They won't run at runtime (e.g. inside injected code).

{$luacode} is probably what you're looking for.
https://forum.cheatengine.org/viewtopic.php?t=618134

If it slows down your game (definitely shouldn't call sleep), doing it asynchronously might help:
Code:
{$luacode}
createTimer(1, function()
  doKeyPress(...)
end)
{$asm}

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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 Feb 11, 2022 7:19 pm    Post subject: Reply with quote

Thank you, ParkourPenguin. I really appreciate your help with this.

What you are saying makes a lot of sense based on what I am experiencing.

I tried using luacode, but the keys still do not seem to be getting sent to the target process.

I even tried incorporating both, doKeyPress and keyDown methods, and also even tried removing the timer. Nothing seems to be working.

Thanks.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4300

PostPosted: Fri Feb 11, 2022 9:02 pm    Post subject: This post has 1 review(s) Reply with quote

In the janky experimentation I'm doing, I guess createTimer might need to be called from the main thread.

Using events like DB suggested in that linked topic would likely be better. Maybe something like this:
Code:
[ENABLE]
{$lua}
if syntaxcheck then return end
if myScriptStuff then
  myScriptStuff.thread.terminate()
  if myScriptStuff.event then
    myScriptStuff.event.setEvent()
  end
  myScriptStuff = nil
end

myScriptStuff = {}
local event = createEvent(false, false)
myScriptStuff.event = event

myScriptStuff.thread = createThread(function(t)
  while not t.Terminated do
    if event.waitFor(0xFFFFFFFF) ~= wrSignaled then break end
    if t.Terminated then break end

    -- your code here
    doKeyPress(69)
    doKeyPress(22531)
  end

  event.destroy()
  if myScriptStuff then myScriptStuff.event = nil end
end)

{$asm}

// your other code
// ...
{$luacode}
myScriptStuff.event.setEvent()
{$asm}
// ...

[DISABLE]
{$lua}
if syntaxcheck then return end
if myScriptStuff then
  myScriptStuff.thread.terminate()
  if myScriptStuff.event then
    myScriptStuff.event.setEvent()
  end
  myScriptStuff = nil
end
{$asm}
// ...

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Feb 12, 2022 6:29 am    Post subject: This post has 1 review(s) Reply with quote

keypress only works on the foreground process

what you can try first before you code too much is to use a timer that presses the keys every 5 seconds

then swap to the game and see if the keys get handled

if not, then it's using a special kind of keyhandling and you have to find out another way to make the game see the keys

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sat Feb 12, 2022 8:40 am    Post subject: Reply with quote

Thank you, guys. I really appreciate your help with this.

@ParkourPenguin - The most recent script that you provided is still not passing keys to the target process. I cannot even begin to guess why, since I do not understand 95% of it.

@DB - My understanding of lua is very basic, but when experimenting yesterday, I was able to get the script to pass keys to the target process by incorporating a timer, but it just kept going and going, and I could not stop it. Unfortunately, based on what you guys have told me, I suspect that the keys are just getting sent, regardless of what is happening with the assembly in my script, so rendering it all useless anyway.

I am really surprised that a simple solution does not seem to exist for this.

Thanks.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sat Feb 12, 2022 9:11 am    Post subject: This post has 1 review(s) Reply with quote

If keypress works then it's simple

your luacode is likely in the same thread that handles keypresses, but doKeyPress releases the key before it continues, so when your luacode returns the keys are up, so the game doesn't see it

use keyDown and keyUp

Code:

{$luacode}
if shouldpresskey then
  keyDown(69)
  keyDown(22531)
else
  keyUp(22531)
  keyUp(69)
end
{$asm}

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sat Feb 12, 2022 11:06 am    Post subject: Reply with quote

Thanks, DB.

Your script is working, sometimes. It is really bizarre.

Similar to the other scripts, the game is slowing down when the luacode is supposed to be executing, so I know that something is happening, which is good. The problem is, it does not always do that for some reason, as if the luacode is not executing. Nothing ever happens when the game does not slow down.

The game does not slow down when using ParkourPenguin's timer createTimer(1, function(), but nothing ever happens when using that. I have tried many different things, but nothing works.

The only time that the game will actually execute the script properly, and function as intended, is if I remove focus from the target, and then move back to the target to put it in focus. But it only works the first time. After that, nothing...unless I remove focus from the target and bring it back into focus again.

The target always slows to a crawl when the code functions properly. It has never happened at full speed.

Also, the only key that seems to work is (69), which is keyboard input for 'E'. The other key (22531) is for controller triangle button...and I have never gotten it to work, no matter what I do. I have changed the game controller settings from keyboard only, controller only and the swap between controller and keyboard option.

I do not think that this is going to work. I understand if you guys do not want to bother more with it. I appreciate all of your help, regardless.

Thanks.

EDIT: I wanted to give ParkourPenguin's most recent script another chance, since I did not test it out enough. It seems to work as intended, but similar to above, it only seems to work when I change focus from the target and bring it back. Similarly, only the keyboard key (69) works, and it only works once. It does not slow the game down, though.

EDIT2: Since I could not get this to work the easy way, I just went ahead and used assembly for everything and made my injections where the game code sends those inputs. It is not ideal, and I would prefer an easier, universal approach, so if anyone else decides to respond to this thread, I will be glad to try something else.

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

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Wed Feb 16, 2022 5:47 pm    Post subject: This post has 1 review(s) Reply with quote

Let's continue this.
1) Are you sure you are using the correct number for keypress? (22531)
Here are some recommendations;

Code:
GamepadRightShoulder   199

GamepadRightTrigger           202


2) Can this code do a test in your case?

https://www.cheatengine.org/forum/viewtopic.php?p=5743626&sid=8553a75e89a21d9d71d310dd38e6399c#5743626

3) It is useful to have a look at this list;

https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkey?view=winrt-22000

I hope your options improve further.

_________________
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
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Wed Feb 16, 2022 6:34 pm    Post subject: Reply with quote

Thanks, AylinCE. It is good to try to expand on this, so I appreciate your help with it.

AylinCE wrote:

1) Are you sure you are using the correct number for keypress? (22531)
-The code was derived from the CE table. I simply set up a hotkey using the controller button that I wanted, saved the CE table, and opened it in notepad++ to see what CE used. That being said, I think that this is not the real issue, since I know that the keyboard key was correct, and it was not working correctly anyway.


AylinCE wrote:

2) Can this code do a test in your case?

https://www.cheatengine.org/forum/viewtopic.php?p=5743626&sid=8553a75e89a21d9d71d310dd38e6399c#5743626
-I will take a look at this and try something when I have more time. Thanks. Looking at this code, however, it seems that it may not be applicable to my situation. As previously pointed out, any lua code would not be executed when I needed it to be unless we use a different approach, since I need the lua code to only run at a specific time, when the assembly code gets executed after the parameters are met.

AylinCE wrote:

3) It is useful to have a look at this list;
-Thanks. If we are able to get a script working properly, then I will look at this more.

I will update this thread once I have had a chance to take another look.

Thanks, again.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1260

PostPosted: Wed Feb 16, 2022 7:29 pm    Post subject: Reply with quote

It's good to see that the topic isn't bogged down.
I hope you have more options for solution.

Note: Do not turn now for the answer. If there is a solution, you will reply when you update it. I don't want to bother you unnecessarily.
Regards, master.

_________________
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
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Wed Feb 16, 2022 8:57 pm    Post subject: This post has 1 review(s) Reply with quote

My try.
The game is Eternium
https://pastebin.com/SNdLhKAm (copy and paste into address-list panel) UPDATED: add Foreground Process check.
It use a global memory which will be write 1 in native code when cooldown reach, then the lua timer reset it to 0 and doKeyPress.
The Timer creation script is enclosed in a 'synchronize' function, so that the script still work in case the script memory record has been set to async executed (may be by accident).

The skill key is [up] for the mage's [immolate] skill.
It seems the inject point of the code only bind to this specific skill.

The timer interval is 60ms, not sure how responsive in other game, but ok for this game.

_________________
- Retarded.
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 Feb 17, 2022 3:07 pm    Post subject: Reply with quote

AylinCE wrote:

2) Can this code do a test in your case?

https://www.cheatengine.org/forum/viewtopic.php?p=5743626&sid=8553a75e89a21d9d71d310dd38e6399c#5743626
-Hello, again. I took another look at this and here is what I determined based on the suggested options that are referenced in that post:

1. The first option is what I ended up going with. I am using the game's code in order to do what I need to do within assembly. I was hoping to avoid this approach because I was looking for something more universal that can be quickly implemented for future targets. The good thing about this approach is that it will work, even when the target is not in focus, but it requires more effort and time and may be unique for all targets.

2. Could not get the second option to work. Even trying to isolate the code so that it only executes at a given time was not working for some reason.

3. The third option requires a 3rd-party application, and would be inconvenient for users.

Thanks so much for your help!

AylinCE wrote:

3) It is useful to have a look at this list;

https://docs.microsoft.com/en-us/uwp/api/windows.system.virtualkey?view=winrt-22000
-Unfortunately, I already looked through this site and many others, and I am unable to get the controller inputs to be recognized, no matter which virtual keys I use.

AylinCE wrote:
I hope your options improve further.
-Thanks! I appreciate your help, as always.



panraven wrote:
My try.
-This indeed works. You are too clever, my friend. Thank you so much for sharing this.

Now, the only problem that I have is being unable to get the controller inputs to be recognized. The keyboard input works great, but I get nothing from the controller. I have tried so many different virtual keys, but nothing is working. Fortunately, not many users may elect to change their settings so that keyboard inputs are ignored. This game has that option, however, so it would be good to try to determine what the issue is.

CE is able to recognize the input (22531) which is for Xbox controller button Y (Triangle button for Playstation), but the game does not, for some reason. The 22531 is in decimal format, presumably, but both, decimal and hex versions do not work. I have tried a number of different label-type versions and VK_ versions as well. Not sure what it needs to be.

I will +rep when I am able. I will not forget.

Thank you, everyone, for your help with this. I really appreciate it.
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
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