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 


Execute a key even when in another program

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
douglaskraft
How do I cheat?
Reputation: 0

Joined: 21 Sep 2024
Posts: 1

PostPosted: Sat Sep 21, 2024 9:06 am    Post subject: Execute a key even when in another program Reply with quote

I'm trying to run a script that reads a value, if it is below it activates an "F1" key.
however I want it to run in the target program, even if I am in Opera

Code:
-- Make sure the game process is open
local al = getAddressList()

-- Defines the F1 key (keycode 0x70 for F1)
location F1_KEY = 0x70
local gamePID = 9596 -- Replace with the game's actual PID

-- Function to send the F1 key to the game, using the game window based on the PID
function sendF1ToGame()
  -- Finds the window associated with the game's PID
  local hwnd = findWindowByProcessID(gamePID)

  if hwnd ~= nil then
    -- Sends the message to press and release F1
    postMessage(hwnd, 0x0100, F1_KEY, 0) -- 0x0100 is the WM_KEYDOWN message (key press)
    postMessage(hwnd, 0x0101, F1_KEY, 0) -- 0x0101 is the WM_KEYUP message (release the key)
  else
  end
end

-- Function to monitor the value in memory
function monitorValue()
  -- Here we define the address and value to be monitored.
  -- Replace "0x3D0F2108" with the correct address of the value.
  local address = 0x3D0F2108

  -- Reads the value of the address
  local value = readInteger(address)

  -- If the value is less than 700, send the F1 command
  if value then
    if value < 700 then
      sendF1ToGame()
    else
    end
  else
  end
end

-- Configure the timer to check the value every second (1000 ms)
timer = createTimer(nil, true)
timer.Interval = 1000 -- 1 second
timer.OnTimer = monitorValue
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3327

PostPosted: Sat Sep 21, 2024 2:27 pm    Post subject: Re: Execute a key even when in another program Reply with quote

douglaskraft wrote:
I'm trying to run a script that reads a value, if it is below it activates an "F1" key.
however I want it to run in the target program, even if I am in Opera

You mean, CE would sent a keypress to the process it is attached to, right?
I think I ran into this problem earlier and there was no solution.
I hope I'm wrong though!
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