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 


Form Wide Hotkey

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Thu Nov 21, 2024 8:49 am    Post subject: Form Wide Hotkey Reply with quote

I am creating a form that I want to close by pressing VK_ESCAPE no matter the currently focused UI element.

This approach will only work if the focused UI element is the form
Code:
form.OnKeyDown = function(sender, key) if key == VK_ESCAPE then form.close() end end
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Thu Nov 21, 2024 2:50 pm    Post subject: Reply with quote

Easiest way is have a button on the form with the Cancel property set to true but the button will have to be visible




you could maybe hook the wndproc using executeCodeLocalEx and handle the message loop manually

or give every control that can get a keyboard focus an onkeydown handler

_________________
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
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1522

PostPosted: Thu Nov 21, 2024 5:28 pm    Post subject: Reply with quote

Code:
UDF1.Show()

if clTmr1 then clTmr1.Destroy() clTmr1=nil end
clTmr1 = createTimer()
clTmr1.Interval=100

clTmr1.OnTimer=function()
 if isKeyPressed(VK_ESCAPE) then
   clTmr1.Destroy()
   UDF1.Close()
   --closeCE()
   --return cafree
 end
 collectgarbage("count")
end

clTmr1.Enabled=true

_________________
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: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Fri Nov 22, 2024 1:39 am    Post subject: Reply with quote

The hotkey in a memory record seems work even ce not in focus.

test memory record, paste following in address list panel

Make a UDF1 form, exit editor and show it.
Select other app to lose ce focus.
CTRL+` (backtick) to close the UDF1 form.

Code:

<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>9</ID>
      <Description>"xxxx close form"</Description>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>{$lua}
if not syntaxcheck and UDF1 then pcall(UDF1.Close) end
[ENABLE]

[DISABLE]

</AssemblerScript>
      <Hotkeys>
        <Hotkey>
          <Action>Toggle Activation</Action>
          <Keys>
            <Key>17</Key>
            <Key>192</Key>
          </Keys>
          <ID>0</ID>
        </Hotkey>
      </Hotkeys>
    </CheatEntry>
  </CheatEntries>
</CheatTable>

_________________
- Retarded.
Back to top
View user's profile Send private message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sun Nov 24, 2024 7:54 am    Post subject: Reply with quote

Thank you everyone

This one works the best:
AylinCE wrote:
Code:
UDF1.Show()

if clTmr1 then clTmr1.Destroy() clTmr1=nil end
clTmr1 = createTimer()
clTmr1.Interval=100

clTmr1.OnTimer=function()
 if isKeyPressed(VK_ESCAPE) then
   clTmr1.Destroy()
   UDF1.Close()
   --closeCE()
   --return cafree
 end
 collectgarbage("count")
end

clTmr1.Enabled=true
Back to top
View user's profile Send private message Visit poster's website
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Tue Nov 26, 2024 7:26 am    Post subject: Reply with quote

I believe this code is causing access violation

Code:
  if hotkeys_timer then hotkeys_timer.Destroy() hotkeys_timer = nil end
  hotkeys_timer = createTimer()
  hotkeys_timer.Interval = 100

  hotkeys_timer.OnTimer = function()
    if isKeyPressed(VK_RETURN) then go_button.DoClick() end
    if isKeyPressed(VK_CONTROL) and isKeyPressed(VK_F) then
      if offset_checkbox.state == cbChecked and offset == true then
        offset_checkbox.state = cbUnchecked
        offset = false
      else
        offset_checkbox.state = cbChecked
        offset = true
      end
    end
    if isKeyPressed(VK_ESCAPE) then
      hotkeys_timer.Destroy()
      form.Close()
    end
    collectgarbage("count")
  end

  hotkeys_timer.Enabled = true


Is it so? Is there a workaround?
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 470

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

PostPosted: Tue Nov 26, 2024 8:15 am    Post subject: Reply with quote

change
Code:

if isKeyPressed(VK_ESCAPE) then
      hotkeys_timer.Destroy()
      form.Close()
    end


to
Code:
 
if isKeyPressed(VK_ESCAPE) then
      hotkeys_timer.Destroy()
      hotkeys_timer=nil
      form.Close()
    end

_________________
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
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