09 January 2021, 06:18 | #1 |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,646
|
Key up detection?
I have hit a brick wall here over something that seems rather stupid but I cannot figure out. How should I approach detecting a key not being pressed anymore?
I feel like I have to make a state machine here, but I have not succeeded in doing so. I would like to: - Press key - Blit a shape - This shape should remain for as long as the key is pressed - Blit back the original state when the key is depressed I'm using Blitz mode and RawStatus. This currently either does not work (a keypress blits the shape but then it stays there), or if it works, it means after the key is depressed, all the default states get blitted back and get themselves blitted every frame (unoptimal and wrong, this will reset ay other shapes i will have in the future) Any help would be appreciated. |
09 January 2021, 12:09 | #2 |
Registered User
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 525
|
Here is a code that reads the space key and detects all possible states: UP, DOWN and RELEASE.
Code:
vwait oldstate = currentstate key = RawStatus($40) If key = 0 then currentstate = #UP If key = -1 then currentstate = #DOWN If oldstate = #DOWN AND currentstate = #UP currentstate = #RELEASE End If |
09 January 2021, 15:07 | #3 |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,646
|
Ahhh you legend, that works quite nicely, yeah.
However, I have a BUNCH of keys here, I need to do this for each and I am not even reading the whole keyboard! Is there any RawStatus for nothing being pressed? $0? |
09 January 2021, 18:30 | #4 | |
Registered User
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 525
|
Quote:
Maybe the easiest way is to have a variable named "AnyKeyDown", and set that to 0 before your key check routines start. And then in all of your key checks you set that variable to 1 if any of those keys were down. Or instead of that you could maybe add together all RawStatus return values of the keys that you check, and if the result is zero, then none of them were pressed. |
|
10 January 2021, 18:21 | #5 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,214
|
Maybe you could use Inkey$ to get whatever key is pressed?
|
11 January 2021, 16:30 | #6 | |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,646
|
Quote:
As it is now, I have a procedure that I call, where I check RawStatus for all the keys I am supposed to be reading. I wonder if I can optimize that but for now it should be OK. Also, I have some shift-key commands, am I correct in nesting these readings , starting with the shift key? Should I use "While"? I thought that'd freeze my program in the procedure so I just used Ifs. I understood Inkey$ requires an enter after typing. It's for reading string input. Not what I want. |
|
11 January 2021, 23:46 | #7 | |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,646
|
Quote:
Code:
Function.s WhichKey {} result$ = "" counter.b = 0 If RawStatus($20) result$ = "A" counter+1 End If If RawStatus($21) result$ = "S" counter+1 End If If counter = 0 result$ = "nothing" End If Function Return result$ End Function Thanks so much! Now I need to tackle the key hold problem, but I might do this in a completely different way, so I'm gonna wait a little bit until I work on other things. [edit] hmmm this keyboard code is a bit of a mess, especially if I introduce shift keys. Will need more looking into. Last edited by Amiga1992; 12 January 2021 at 01:34. |
|
12 January 2021, 16:10 | #8 | |
Registered User
Join Date: Nov 2015
Location: Vaasa, Finland
Posts: 525
|
Quote:
Code:
If RawStatus(Shift rawkey code) result$ + "SHIFT" End If But if that doesn't work, then the standard way how I would handle it would be to have two routines; one checks the keys without Shift, and the other one with Shift. So the shift status is checked only once before the two routines, and depending on it's status one of the routines is selected. |
|
12 January 2021, 16:57 | #9 | |
Registered User
Join Date: May 2001
Location: ?
Posts: 19,646
|
Quote:
Now the problem I noticed, is that sometimes, it registers also the non shifted value. Like if I am looking for Shift+A, sometimes the program, while I keep Shift pressed and mash A, will read just A. I don't know WHY this happens because it shouldn't happen, but it could be because those checks are done before the shift checks, so maybe if I put the shift checks at the top of the keyboard reading routine, it might work better. I'm really annoyed at how Blitz really needs you to put things in certain places but no reference to this is mentioned in the docs. you just learn with trial by fire. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
SMC detection | StingRay | support.WinUAE | 19 | 12 November 2022 17:47 |
Amiga key=Windows key and problems there of | darkhog | support.WinUAE | 1 | 31 March 2017 22:08 |
Collision Detection | sandruzzo | Coders. General | 5 | 10 June 2016 12:50 |
FS-UAE 2.5.6dev Amiga Key (Windows key) pops up the start menu | Marskilla | support.FS-UAE | 3 | 23 September 2014 23:18 |
Amiga 'HELP' key - tribute thread to the abandoned key... | Paul_s | Amiga scene | 22 | 23 July 2009 12:15 |
|
|