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 


Couple of questions regarding Textboxes and Buttons

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Sun Sep 09, 2018 1:45 am    Post subject: Couple of questions regarding Textboxes and Buttons Reply with quote

Hello!
So i'm working on a form, and i need some help.
First of all, i have a textbox, with a button near it. When the button is pressed, an address gets set to the value of the textbox. My issue is that i want to make it work when i press the enter key in the textbox. I tried both OnKeyDown, and OnKeyPress, but in both cases, the address value gets set when pressing number buttons on my keyboard. Is what i want to do possible?
And second, i have an other button, that when pressed, increases the value of an other address. Is there a way to make it like when you hold the button pressed, the value keeps increasing? Is there a "State" function like checkboxes that i could use on a timer?
Thanks a lot!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Sun Sep 09, 2018 8:49 am    Post subject: Reply with quote

Gou wrote:
I tried both OnKeyDown, and OnKeyPress, but in both cases, the address value gets set when pressing number buttons on my keyboard.
Did you check what the pressed key was?
Code:
if key == VK_RETURN then
  --...
end

Gou wrote:
Is there a "State" function like checkboxes that i could use on a timer?
Toggle the timer on mouse down and mouse up.
_________________
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
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Sun Sep 09, 2018 11:03 am    Post subject: Reply with quote

Yes. In that case, it doesnt work at all. I mean, this is correct syntax, isnt it?
Code:
function textboxKeyPress(sender, key)
 if key == VK_RETURN then
  writeFloat(somewhere, something)
 end
  return key
end

About the second one, oh. You are right. I didnt think about that. Sorry Very Happy
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Sep 09, 2018 1:53 pm    Post subject: Reply with quote

OnKeyPress receives the key, not the virtual keycode.

so check if key is \n

_________________
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
Gou
Cheater
Reputation: 0

Joined: 02 Oct 2017
Posts: 39

PostPosted: Tue Sep 11, 2018 10:57 am    Post subject: Reply with quote

So it should be like that?
Code:
if key == \n then etc

Because in that case i'm getting an error. It does execute it if i add ' ', but it doesn't work.
I'm sorry but what am i missing?
Thanks once again!
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Sep 11, 2018 11:15 am    Post subject: Reply with quote

i'm not sure how to check that in lua. Perhaps string.byte or something


easiest is OnKeyDown and check for VK_ENTER (or 13) there

_________________
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
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4299

PostPosted: Tue Sep 11, 2018 11:28 am    Post subject: Reply with quote

keyPress gets the carriage return but not the newline. Use '\r' instead or press Ctrl+Enter for the newline character.

You should really just use the keyDown event IMO. The button should be pressed when the enter key is pressed. That has nothing to do with characters being inserted into the edit control.

Alternatively, if that's the only button, you can set its Default property to true.

_________________
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
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Tue Sep 11, 2018 7:36 pm    Post subject: Reply with quote

something like this?. Accept and execute 'bla..bla..bla' command by key press 'ENTER'. Old script sttill work..

Code:
f = createForm()
tb = createEdit(f)

virtual_keys = {}
for i, v in pairs(_G) do
  if type(i) == "string" then
    if i:sub(1, 3) == "VK_" then
     virtual_keys[v] = i
     key1 = virtual_keys[v]
   end
  end
end


function tbKeyDown(sender, key)
  input = tb.Text
  key_check = 'VK_RETURN'
  a = virtual_keys[key]
  if a == key_check and input ~= '' then
  print('you just typed...'..input)   ----- your code here
  return key
  end
end

tb.onKeyDown = tbKeyDown
f.show()

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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