Here I want to count each remote key press. I want to do following way
If “Down” key pressed for the first time => I can do something
If “Down” key pressed for the second time => I can do something more
A step by step job.
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if(key = "down")
//do something
end if
//and again if pressed, do something
end if
return handled
end function
So how can I count the remote down key press ? I hope you got the idea.
You need to persist the state between events. “m” comes to mind.
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if m.key_cnt = invalid then m.key_cnt = {}
if m.key_cnt[key] = invalid then m.key_cnt[key] = 0
m.key_cnt[key] += 1
if key = "down" and key.key_cnt[key] = 3:
//do something on the 3rd press of Down :slightly_smiling_face:
end if
end if
return handled
end function
“EnTerr” wrote:
You need to persist the state between events. “m” comes to mind.
function onKeyEvent(key as String, press as Boolean) as Boolean
handled = false
if press then
if m.key_cnt = invalid then m.key_cnt = {}
if m.key_cnt[key] = invalid then m.key_cnt[key] = 0
m.key_cnt[key] += 1
if key = "down" and key.key_cnt[key] = 3:
//do something on the 3rd press of Down :slightly_smiling_face:
end if
end if
return handled
end function
Thank you, bro. But I got an error - Syntax Error. (runtime error &h02), I have a doubt , is it key.key_cnt[key] or m.key_cnt[key] ?.
“RENJITHVR4” wrote:
Thank you, bro. But I got an error - Syntax Error. (runtime error &h02), I have a doubt , is it key.key_cnt[key] or m.key_cnt[key] ?
Right, you got it - should been m.key_cnt[key].
This is just something i typed off-hand just for you - not something i have used nor tested. There be typos. The important part is to get the idea.