View previous topic :: View next topic |
Author |
Message |
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Mon Jul 19, 2021 8:19 pm Post subject: check for keypress once |
|
|
how do i check for keypress once? so if the user holds a certain key down, they have to press the key again to run a function again.
|
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Mon Jul 19, 2021 9:49 pm Post subject: |
|
|
Code: | if form then form.destroy() form = nil end
form = createForm()
form.Position = poDesktopCenter
local b1 = createButton(form)
b1.Left=115 b1.Top=30 b1.Width=90 b1.caption="Click me!"
local clicked=0
b1.OnClick=function()
clicked=tonumber(clicked) + 1
if clicked==2 then
showMessage("You got me!")
clicked=0
else
showMessage("Keep searching. ;)")
end
end |
|
|
Back to top |
|
|
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Mon Jul 19, 2021 10:06 pm Post subject: |
|
|
i dont wanna sound rude but i think i should explain it abit more, im trying to check if a user pressed a key on the keyboard e.g Q for example. i've tried using timers to check isKeyPressed and hotkeys but if i add + 1 to some variable, it will keep spamming + 1 to the variable unless the user stops pressing the key.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Mon Jul 19, 2021 10:23 pm Post subject: |
|
|
Create a hotkey that checks a guard variable. If it's unset, then set it, create a timer to unset it when the key isn't pressed anymore (and destroy the timer), and do whatever else you want.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
HexaG0n Advanced Cheater Reputation: 0
Joined: 29 Mar 2021 Posts: 64
|
Posted: Mon Jul 19, 2021 11:12 pm Post subject: |
|
|
i think i got it:
Code: | a = 0
ta=createTimer()
ta.Interval=1
ta.OnTimer=function(ta)
if isKeyPressed(VK_A) then
a = a + 1
else
a = 0
end
if a == 1 then
print('Pressed A!')
ta.destroy()
end
end |
thanks
|
|
Back to top |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Tue Jul 20, 2021 12:34 am Post subject: |
|
|
It turns out that this is a keyboard key!
You can simply be presented with different options and you get the idea that helps you.
Here is an option:
Code: | if htkey then htkey.Destroy() htkey=nil end
if htkeyTimer then htkeyTimer.Destroy() htkeyTimer=nil end
htkeyTimer=createTimer() htkeyTimer.Interval=10 htkeyTimer.Enabled=true
function clickKey()
print("Hello User")
end
htkeyTimer.OnTimer=function()
if isKeyPressed(VK_F8) then
htkeyTimer.Enabled=false
local answer = messageDialog("Do you confirm to turn on the function?", mtWarning, mbYes, mbNo)
if answer == mrYes then
htkey=createHotkey(clickKey, VK_F9)
showMessage("Press the 'F9' key to run the function.");
else
if htkey then htkey.Destroy() htkey=nil end
htkeyTimer.Enabled=true
end
end
end |
|
|
Back to top |
|
|
WhiteSnoop How do I cheat? Reputation: 1
Joined: 15 May 2009 Posts: 7 Location: http://alino.ucoz.com
|
Posted: Thu Jul 22, 2021 12:16 pm Post subject: |
|
|
I figured I'd share my way of tackling the issue. Keep in mind I very much optimized it into a function because I needed a table of hotkeys to process
Code: | function hotkeyDebug(tbl)
for i, entry in pairs(tbl) do
local key = isKeyPressed(entry.hotkey)
if not entry.isHolding and key then
entry.func()
entry.isHolding = true
elseif not key then
entry.isHolding = false
end
end
end |
Then I have this in my actual mission script
Code: | local M1_debugKeys = {
{
hotkey = VK_F11,
func = function()
setGameStatus(1)
end,
isHolding = false,
},
{
hotkey = VK_NUMPAD0,
func = function()
teleportMainPlayerToWaypoint(419)
end,
isHolding = false,
},
}
hotkeyDebug(M1_debugKeys)
|
|
|
Back to top |
|
|
|