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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
newpie
- Livecode Opensource Backer

- Posts: 155
- Joined: Sat Jun 29, 2013 11:24 pm
Post
by newpie » Tue Feb 02, 2016 1:02 am
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
Code: Select all
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
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Feb 02, 2016 2:15 am
Hi NewPie,
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
that is a tricky one.
I came up with this solution
put this code into a field
Code: Select all
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.
Kind regards
Bernd
-
newpie
- Livecode Opensource Backer

- Posts: 155
- Joined: Sat Jun 29, 2013 11:24 pm
Post
by newpie » Tue Feb 02, 2016 2:43 am
Thats great, works like a charm. Thank you for taking the time and -- comments as well.
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Feb 02, 2016 2:59 am
Is this too simple? In the card script:
Code: Select all
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
-
newpie
- Livecode Opensource Backer

- Posts: 155
- Joined: Sat Jun 29, 2013 11:24 pm
Post
by newpie » Tue Feb 02, 2016 4:26 am
Hey dunbarx. Does your code let you specify the keys to be pressed and only fire when those keys are pressed within so much time (ex: second)?
-
newpie
- Livecode Opensource Backer

- Posts: 155
- Joined: Sat Jun 29, 2013 11:24 pm
Post
by newpie » Tue Feb 02, 2016 5:05 am
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..
Thanks
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Tue Feb 02, 2016 6:16 am
Hi.
EDITED...
Make a field on a new card. Put this in the card script:
Code: Select all
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.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Tue Feb 02, 2016 10:54 am
Hi Newpie,
but I guess the scanners are too fast and it doesn't pick it up
are you sure the scanner sends "pure" rawkeys and not some additional stuff?
Could you explain your use case a bit more?
The codes should be fast enough (I guess)
Kind regards
Bernd
-
newpie
- Livecode Opensource Backer

- Posts: 155
- Joined: Sat Jun 29, 2013 11:24 pm
Post
by newpie » Fri Feb 26, 2016 3:57 am
Hey bn, sorry for the late reply, I tested with another barcode scanner and it works great. Wanted to let you know. Thank you everyone for your help.
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Fri Feb 26, 2016 8:40 am
Hey newpie,
thanks for letting us know. It is always nice to hear of the ultimate outcome of a problem.
Kind regards
Bernd