Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
Hello, I was trying to figure out how to do a multi down trigger using non-function keys specifically.
So for example if a user does a certain sequence of keys ( example= "o+p+q" ) within a second or so on the keyboard itwould trigger the answer code. Tried the below, but doesn't compile
on rawKeyDown theKeyNumber
if the theKeyNumber is 111 and theKeyNumber is 112 and theKeyNumber is 113 then
answer "trigger"
end if
end rawKeyDown
Thank you for any help. Here is the theKeyNumber reference for windows.
a = theKeyNumber: 97
b = theKeyNumber: 98
c = theKeyNumber: 99
d = theKeyNumber: 100
e = theKeyNumber: 101
f = theKeyNumber: 102
g = theKeyNumber: 103
h = theKeyNumber: 104
i = theKeyNumber: 105
j = theKeyNumber: 106
k = theKeyNumber: 107
l = theKeyNumber: 108
m = theKeyNumber: 109
n = theKeyNumber: 110
o = theKeyNumber: 111
p = theKeyNumber: 112
q = theKeyNumber: 113
r = theKeyNumber: 114
s = theKeyNumber: 115
t = theKeyNumber: 116
u = theKeyNumber: 117
v = theKeyNumber: 118
w = theKeyNumber: 119
x = theKeyNumber: 120
y = theKeyNumber: 121
z = theKeyNumber: 122
local sTriggerCode = "111,112,113" -- you could add to this or change this, see below for timing
local sStartMS = ""
local sCode = ""
on rawKeyUp pKey
if not (pKey is among the items of sTriggerCode) then
put "" into sCode
put "" into sStartMS
pass rawKeyUp
end if
if pKey is item 1 of sTriggerCode and sStartMS = "" then
put the milliseconds into sStartMS
put pKey & comma into item 1 of sCode
pass rawKeyUp
end if
put itemOffset(pKey,sTriggerCode) into tOffset
if tOffset > 1 then
if the milliseconds - sStartMS > 1000 then -- increase time if you want more than three letters to be tested
put "" into sStartMS
put "" into sCode
pass rawKeyUp
end if
put the number of items of sCode into tTest
if tOffset = tTest + 1 then
put pKey & comma after sCode
if the number of items of sCode = the number of items of sTriggerCode then
put "" into sStartMS
put "" into sCode
answer "you got it"
pass rawKeyUp
end if
pass rawKeyUp
else
put "" into sStartMS
put "" into sCode
pass rawkeyUp
end if
else
put "" into sStartMS
put "" into sCode
pass rawkeyUp
end if
end rawKeyUp
in my limited test it did work if you are fast enough (up to 1000 milliseconds), you can add to the passcode but you would have to increase the time allowed for a hit.
global keyList
on keyDown tKey
put tKey after keyList
if the length of keyList >= 3 then
answer "You pressed:" && keyList
put "" into keyList
end if
end keyDown
So I finally got to test bn coding with a scanner. It works when you do it on keyboard, but I guess the scanners are too fast and it doesn't pick it up. I am sure that code can be useful to some coders in the future though for various things. Any ideas for scanner please let me know. The scanner I have cannot do function buttons like Alt, ctrl, ect..
global keyList,lastStart
on keyDown tKey
if keyList = "" then put the ticks into lastStart
put tKey after keyList
switch
case the ticks -lastStart > 120
put "" into keyList
break
case the length of keyList < 3
put the ticks into lastStart
break
case the length of keyList >= 3
put "You pressed:" && keyList into fld 1
put "" into keyList
break
end switch
put the ticks into lastStart
end keyDown
If you press three keys in succession, all within a two seconds, you will get an answer. If you delay, you get a restart. This can be made more robust; I do not like to have things so dependent on other things. But it was late...
Craig
Last edited by dunbarx on Tue Feb 02, 2016 3:15 pm, edited 2 times in total.