|
Post by rosy on Jan 5, 2021 12:07:32 GMT -6
Is it possible to detect multiple keys? Sometimes you can detect only 2 at a time, sometimes more, depending on what keys ...
|
|
|
Post by n00b on Jan 5, 2021 12:28:28 GMT -6
Yes. The Key() function will return true for every key that is pressed.
|
|
|
Post by rosy on Jan 5, 2021 17:20:29 GMT -6
This, unfortunately, not with me ...
|
|
|
Post by n00b on Jan 5, 2021 18:11:33 GMT -6
Try running this.
WindowOpen(0, "Multi Key Test", WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, 640, 480, 0)
SetColor(RGB(255,255,255))
While Not Key(K_ESCAPE) Cls Locate(0, 0) Keys_Pressed$ = "" For i = K_A To K_Z If Key(i) Then Keys_Pressed$ = Keys_Pressed$ + Chr$(i) + " " End If Next PrintS("Keys = " + Keys_Pressed$) Update Wend
|
|
|
Post by rosy on Jan 6, 2021 2:50:05 GMT -6
It is as I wrote. For example: The c v b keys - when pressed simultaneously - shows nothing, when in sequence - shows only the first 2 and does not show any other additionally pressed key.
|
|
|
Post by n00b on Jan 6, 2021 15:24:28 GMT -6
That is a hardware limitation of keyboards in general. You will notice that different keyboards will have different keys that can be registered simultaneously. You can do a google search to find out more about it.
|
|
|
Post by johnno56 on Jan 6, 2021 15:57:51 GMT -6
I tried your example... The most keys I could register was 5. On average about 3.
So many keys to register... Are we planning a 'piano' for a tablet? Just curious... lol
|
|
|
Post by rosy on Jan 6, 2021 16:49:32 GMT -6
Soccer. The diagonal movement is 2 keys + arrow and we have a problem.
|
|
|
Post by tbird on Jan 6, 2021 18:51:52 GMT -6
Just curious do you need to know the key returned as opposed to just looking for each key individually?
|
|
|
Post by rosy on Jan 7, 2021 8:24:26 GMT -6
I do not understand...
|
|
|
Post by tbird on Jan 7, 2021 9:26:14 GMT -6
Sorry I didn't write my question clearly.
Do you require to see any keys that are pressed, as in when the user presses a key "k" for example, scan for any keys, and return the key pressed whatever it is, in this case "k"
As opposed to an If statement looking for the specific keys you need, If Key(K) Then DoSomething() End If
I do apologize I am writing this on a phone.
|
|
|
Post by rosy on Jan 7, 2021 11:33:17 GMT -6
If I want to check K, I have to scan all ...
|
|
|
Post by tbird on Jan 7, 2021 12:09:46 GMT -6
Well in my demo I can push 4-5 keys simultaneously and they all register, but I don't scan all the keys waiting for input RC does that already doing it manually again is redundant I simply look for the key as in If Key(K_UP) Then....etc.
If I am misunderstanding how your doing it I apologize, but in n00bs example that would be the inefficient way of looking for a key press....and possibly troublesome, I am not sure.
|
|
|
Post by tbird on Jan 8, 2021 20:54:51 GMT -6
In case of anymore confusion I am finally back at my laptop so I can give an example:
Screen_Width = 800 Screen_Height = 600
WindowOpen(0, "Key Test", 0, 0, Screen_Width, Screen_Height, 0) CanvasOpen(0, Screen_Width, Screen_Height, 0, 0, Screen_Width, Screen_Height, 0) Canvas(0) SetColor(RGB(100, 255, 80))
While NOT Key(K_Escape) ClearCanvas() If Key(K_A) Then Rect(30, 30, 30, 30) End If If Key(K_S) Then Rect(65, 30, 30, 30) End If If Key(K_D) Then Rect(100, 30, 30, 30) End If If Key(K_U) Then Rect(135, 30, 30, 30) End If If Key(K_P) Then Rect(170, 30, 30, 30) End If If Key(K_Space) Then Rect(205, 30, 30, 30) End If Update() Wend So push A, S, D, U, P, & Spacebar and they all register, at the same time.
|
|
|
Post by johnno56 on Jan 9, 2021 0:02:40 GMT -6
Cool... works for me... does it come in blue? lol
|
|