View previous topic :: View next topic |
Author |
Message |
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Sun Sep 09, 2018 1:45 am Post subject: Couple of questions regarding Textboxes and Buttons |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4299
|
Posted: Sun Sep 09, 2018 8:49 am Post subject: |
|
|
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 |
|
|
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Sun Sep 09, 2018 11:03 am Post subject: |
|
|
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
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Sun Sep 09, 2018 1:53 pm Post subject: |
|
|
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 |
|
|
Gou Cheater Reputation: 0
Joined: 02 Oct 2017 Posts: 39
|
Posted: Tue Sep 11, 2018 10:57 am Post subject: |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25295 Location: The netherlands
|
Posted: Tue Sep 11, 2018 11:15 am Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4299
|
Posted: Tue Sep 11, 2018 11:28 am Post subject: |
|
|
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 |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Tue Sep 11, 2018 7:36 pm Post subject: |
|
|
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 |
|
|
|