Keyboard trouble... :(
BlitzPlus Forums/BlitzPlus Programming/Keyboard trouble... :(
| ||
I have written a very nice piece of software down here, using Blitz3D. Now, I have just purchased BlitzPlus and have recompiled it (I did not use any 3D - just plain 2D stuff). The recompiled (with BlitzPlus) version rubs much smoother. It is ALMOST perfect. But the keyboard logic has gone to space... I had to write some chunk of code to deal with auto-repeat, del, tab, backspace, arrow keys, and the like. And now none of it works. Well, some of it works, but with side effects. Let me just check if I am right... B3D did not catch CONTROL+Key combinations (or ALT+Key for that matter) with the GetKey() function. So, one would have to work around it by using KeyDown() and KeyHit() functions. Thatīs fine with me. It was not very difficult and worked perfectly well. Please, understand that I am not trying to explain it here, I am just trying to make sure that I understand what is going on, myself... Now that I have recompiled it, I have to throw away the specialized code I have written, because getKey() now is capable of (and does) handling any key combination, by using 64 bits for the "virtual key" code (or something like that). So, I can simply use GetKey() and check if it is the ALT+Z "virtual key", instead of having to check if the ALT key is being held down when GetKey() returns the ASCII code for "Z". Is that it? If so, where can I find more info about it --- if there is anything else I should be aware of, concerning keyboard input, that is... I would appreciate any help on this. Thank you, /R |
| ||
Yeah, right... I got it :^). B+ deals with keyboard beautifuly, even when you are not using messages. Converting my code was piece of cake. And now it is much more readable, too... /R |
| ||
the first thing that a new b+ update should have imo, is a proper keysystem, including all kinda luxery to configure, such as keyrepeat and more.. (such as: when you hit [alt]+[q], and you release the [alt] first, you shouldn't get a [q] trigger for a while, only after the usual key-delay. Since last week I am busy with a key-controlled app (a music-tracker!) and luckily blitzcoder.com was in the air when this site was down. This is what Cyberseth proposed to my initial app: app=CreateWindow("..",0,0,640,480) Global quit=False Global c=CreateCanvas(32,32,512,512,app) Global x,y Global delaykey, delaytime timer = CreateTimer(30) ; 30 FPS ; Make an array of all the keys you want to check for ; so we can store their numbers, for delay purposes Dim Key(20,1) Dim KeyDn(20) Key(0,0)=200 Key(1,0)=208 Key(2,0)=203 Key(3,0)=205 Key(4,0)=15 key(4,1)=-42 ; Let's say "-" means "DONT PRESS IT" Key(5,0)=15 key(5,1)=42 delaykey=-1 ; none of the above Repeat WaitEvent() If EventID()=$803 If EventSource()=app quit=True EndIf EndIf If EventID()=$4001 ; Every timer tick, we can update the game ; If you want to you could use EventData() to find the number of ticks ; elapsed and then a For..Next loop to accurately update the game ; but for now it's unnecessary. ; To do all this key stuff, let's go through our Key(i,j) array ; and check if the keys have been pressed. I made it a two-dimensional ; array so we can have more than one scancode for each key... For i=0 To 20 ok=1 ; a variable to check whether this is OK If Key(i,0)=0 Then ok=0 For j=0 To 1 If Key(i,j)<0 Then ; if <0 then check it is NOT pressed If KeyDown(-key(i,j))=True Then ok=0 ; not ok, we want it to be False End If If Key(i,j)>0 Then ; if >0 then check it is pressed If KeyDown(key(i,j))=False Then ok=0 ; not ok, we want it to be True End If Next If ok If KeyDn(i)=0 Then ; If KeyHit delaykey=i If delaytime>0 delaytime=1 End If KeyDn(i)=1 ; Set KeyDown If delaytime=0 Or delaytime>7 ; if keyhit or delay>10 frames Select i Case 0 ; 200 y=y-1 Case 1 ; 208 y=y+1 Case 2 ; 203 x=x-1 Case 3 ; 205 x=x+1 Case 4 ; 15, NOT 42 x=x+1 Case 5 ; 15, 42 x=x-1 End Select End If delaytime=delaytime+1 Else If KeyDn(i) Then ; key off KeyDn(i)=0 End If End If Next For i=0 To 20 If KeyDn(i)=0 And delaykey=i delaykey=-1 delaytime=0 End If Next draw() End If Until quit End Function draw() SetBuffer CanvasBuffer(c) Cls Rect x*4,y*4,8,8,True Text 20,100,x+" "+y Text 20,115,"Delay Time: "+delaytime Text 20,130,"Delay Key : "+delaykey If delaykey<>-1 Text 20,145,"Delay Scancode : "+Key(delaykey,0) FlipCanvas c End Function |