Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Configured the key. How is key cancel?
#1
  Hi Quarchodronand other programmers.

I know how to configure the keys by clicking on which something will happen. But how do I cancel these settings? How do I make the key stop calling an action? 
Code:
            addEventHandler("onKey",function(key)
{
    if (key == KEY_7)
    {
setFreeze(true);
    }
})
I need "F7" to work as a freeze initially.
And then return " F7 " to its original form, so that the key does not start freezing.


All that happens is that I delete the "onKey" event . And in General, everything stops working (chat, list of players)
Reply
#2
demor140202 Wrote:I know how to configure the keys by clicking on which something will happen. But how do I cancel these settings? How do I make the key stop calling an action?

Hm.. that depends of your "needs".
If you only want a F7 key to stop working after pressing it, you can always write something like this:

Squirrel Script
  1. local freezeKeyPressed = false
  2.  
  3. addEventHandler("onKey", function(key)
  4. {
  5. switch (key)
  6. {
  7. case KEY_F7:
  8. if (!freezeKeyEnabled)
  9. {
  10. setFreeze(true)
  11. freezeKeyEnabled = true
  12. }
  13. break
  14. }
  15. })



In order to re-enable the F7 functionallity, change the content of the "freezeKeyEnabled" variable back to "false".
Also, maybe you don't want to "disable" the key, but rather after pressing it second time, call the setFreeze(false).

To do that, you can make something like this:
Squirrel Script
  1. local menuVisible = false // dummy variable for example purposes
  2.  
  3. addEventHandler("onKey", function(key)
  4. {
  5. switch (key)
  6. {
  7. case KEY_F7:
  8. menuVisible = !menuVisible // negating a variable content
  9. setFreeze(menuVisible)
  10. break
  11. }
  12. }



Also, do note, that you can add more than one function to a specific event using addEventHandler function.
Reply
#3
(24.02.2020, 12:50)Patrix Wrote:
demor140202 Wrote:I know how to configure the keys by clicking on which something will happen. But how do I cancel these settings? How do I make the key stop calling an action?

Hm.. that depends of your "needs".
If you only want a F7 key to stop working after pressing it, you can always write something like this:

Code:
local freezeKeyPressed = false

addEventHandler("onKey", function(key)
{
    switch (key)
    {
        case KEY_F7:
            if (!freezeKeyEnabled)
            {
                setFreeze(true)
                freezeKeyEnabled = true
            }
            break
    }
})

In order to re-enable the F7 functionallity, change the content of the "freezeKeyEnabled" variable back to "false".
Also, maybe you don't want to "disable" the key, but rather after pressing it second time, call the setFreeze(false).

To do that, you can make something like this:
Code:
local menuVisible = false // dummy variable for example purposes

addEventHandler("onKey", function(key)
{
    switch (key)
    {
        case KEY_F7:
            menuVisible = !menuVisible // negating a variable content
            setFreeze(menuVisible)
            break
    }
}

Also, do note, that you can add more than one function to a specific event using addEventHandler function.
Thanks, buddy.
Reply


Forum Jump:


Users browsing this thread: