zpq
New Member
Posts: 4
|
Post by zpq on Sept 21, 2021 13:51:08 GMT
Hi I am looking for help with a simple way to get a single key that is pressed. I don't want to use input and I can't seem to do it with scan.
Thanks in advance
|
|
|
Post by tsh73 on Sept 21, 2021 14:02:19 GMT
I think the only way to get key pressed is event in graphicbox, which is more or less OK for games. See INKEY.bas in examples folder. Help has topic "Using Inkey$" with further links.
|
|
zpq
New Member
Posts: 4
|
Post by zpq on Sept 21, 2021 14:10:36 GMT
Thanks That means having 2 windows open. Someone must have found a way around this? can it be done with liberty basic?
|
|
|
Post by tsh73 on Sept 21, 2021 14:25:29 GMT
What for you need check for single key? May be there is other way?
If you have mainwin (console) program, there is input$(1), but it is blocking - program will wait until you press a key
10 a$=input$(1) scan print a$;"."; goto 10
In Liberty Basic you can call Wndows API, I believe GetAsyncKeyState works OK (you can search for it on LB forum)
|
|
zpq
New Member
Posts: 4
|
Post by zpq on Sept 21, 2021 17:40:56 GMT
The project is to create a time card calculator using military time with 100ths of an hour. I want to restrict a number input to 2 digits. This is to avoid operator error. I think my answer is to create a numerical keypad with the button function.
|
|
|
Post by tsh73 on Sept 21, 2021 19:19:21 GMT
I remember PALM had time selector as [hours]:[d1][d2] <up down arrows> you can select any of three fields, and pressing up or down cycle in 0..23 - 0..9 ranges Really, worked pretty neat with a stylus.
So based on that - have a look at this, with comboboxes (only problem as of now, you can enter any text in comboboxes' editors. But you can validate it for 0..23, 0..9 range)
' Form created with the help of Freeform-J v.261006 ' Generated on Sep 21, 2021 at 22:05:34
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
dim arrayH$(24) for i = 0 to 23 arrayH$(i+1)=right$(str$(100+i),2) next
dim arrayD$(10) for i = 0 to 9 arrayD$(i+1)=str$(i) next
combobox #main.cmbH, arrayH$(, [dummy], 14, 16, 64, 95 button #main.OK, "Get the time", [GetTheTime], UL, 206, 11, 122, 25 texteditor #main.log, 206, 51, 328, 300 combobox #main.cmbD1, arrayD$(, [dummy], 86, 16, 48, 100 combobox #main.cmbD2, arrayD$(, [dummy], 142, 16, 48, 100 menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "time selector example" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" 'cur time tim$=time$() h$=left$(tim$,2) d1$=mid$(tim$,4,1) d2$=mid$(tim$,5,1) #main.cmbH, "select "; h$ #main.cmbD1, "select "; d1$ #main.cmbD2, "select "; d2$ #main.log, "Current time: ";tim$
wait
[quit.main] Close #main END
[GetTheTime] #main.cmbH, "contents? h$" #main.cmbD1, "contents? d1$" #main.cmbD2, "contents? d2$" tim$=h$+":"+d1$+d2$ #main.log, "Entered time: ";tim$ wait
[dummy] wait
EDIT
So 12.75 is possible? Really my code allows that - but only because I forgot to restrict higher minutes to 0..5 :)
|
|
|
Post by tsh73 on Sept 21, 2021 19:35:17 GMT
some fixes and checks
'time selector 'v2 - restrict minutes to 0...59 instead of 0..99
nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
dim arrayH$(24) for i = 0 to 23 arrayH$(i+1)=right$(str$(100+i),2) next
dim arrayD1$(10) for i = 0 to 5 arrayD1$(i+1)=str$(i) next
dim arrayD2$(10) for i = 0 to 9 arrayD2$(i+1)=str$(i) next
statictext #main.lblHH, "hh", 14, 5, 20, 20 combobox #main.cmbH, arrayH$(, [dummy], 14, 25, 54, 95 statictext #main.lbl1, ":", 75, 5, 10, 20 statictext #main.lbl1, ":", 75, 25, 10, 20 statictext #main.lblHH, "m", 86, 5, 20, 20 combobox #main.cmbD1, arrayD1$(, [dummy], 86, 25, 48, 100 statictext #main.lblHH, "m", 142, 5, 20, 20 combobox #main.cmbD2, arrayD2$(, [dummy], 142, 25, 48, 100
button #main.OK, "Get the time", [GetTheTime], UL, 206, 30, 122, 25 texteditor #main.log, 206, 60, 328, 290
menu #main, "Edit" '<--- Texteditor Menu can be moved but not removed.
open "time selector example" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10" 'cur time tim$=time$() h$=left$(tim$,2) d1$=mid$(tim$,4,1) d2$=mid$(tim$,5,1) #main.cmbH, "select "; h$ #main.cmbD1, "select "; d1$ #main.cmbD2, "select "; d2$ #main.log, "Current time: ";tim$
wait
[quit.main] Close #main END
[GetTheTime] #main.cmbH, "contents? h$" #main.cmbD1, "contents? d1$" #main.cmbD2, "contents? d2$" 'range check. <= 'cause val("garbage")=0 if val(h$)<=0 or val(h$)>23 then h$="00" if val(d1$)<=0 or val(d1$)>5 then d1$="0" if val(d2$)<=0 or val(d2$)>9 then d2$="0"
tim$=h$+":"+d1$+d2$ #main.log, "Entered time: ";tim$ wait
[dummy] wait
|
|
zpq
New Member
Posts: 4
|
Post by zpq on Sept 22, 2021 13:16:59 GMT
Hi Thanks, it is an option that I did not think of. It can be difficult to stop operator error. I used to write DOS shareware and I had a beta tester that could break almost any program that required user input. People ignore documentation and try to put in whatever they want.
|
|
|
Post by tsh73 on Sept 22, 2021 15:36:47 GMT
He 's got talent! ;)
|
|