I'm trying to implement a system for my Star Trek game where pressing and holding one key, and then pressing another performs a function. For example, pressing and holding the + key, and then pressing the 1 key sets 1/4 impulse power, and then releasing the + key engages that speed change. I plan to use Direct Input. Any ideas?
Certainly! The only minor complication is that the keys you've specified are on separate rows for direct input detection, but the way I would do it is as follows (assuming that 1 = 1/4 impulse power, 2 = 1/2 impulse, etc.)

1. Check the 5th key row for the [+] key; if it's pressed, then proceed with the following.
2. Check the 2nd key row for the [1] or [4] keys and if one of these are pressed then set 1/4 or full impulse power accordingly.
3. Check the 3rd key row for the [2] key and if pressed then set 1/2 impulse power.
4. Check the 4th key row for the [3] key and if pressed then set 3/4 impulse power.

Does that help? Smile
That is correct!

Similar setup for warp speed. The function key is [*], and then the numbers 1-9 for Warp 1-9, respectively.

And some other functions may work this way too, not sure.

Thanks.
Cool! If the number keys are used in more than one place, then it might be more efficient to switch the detection around, eg:

1. Check the 2nd key row for [1], [4] or [7]. If one is pressed, check the 5th row for [+] or [*] and do the required action (no action for [+] if [7] was pressed).
2. Same for the 3rd key row scanning for [2], [5] or [8].
3. Same for the 4th key row scanning for [3], [6] or [9].

I think the code will be more or less the same size either way though, as both ways you're scanning for 18 possible key combinations (only 13 of which will actually perform an action).
Jim e's routine is really nice, too:
http://www.ticalc.org/archives/files/fileinfo/239/23966.html

It's pretty ingenious, really:

Code:
;-----------------------------------
;Keyin by James Montelongo
;Gets keys and stores it in
;statvars so (iy) can check it
;input=none
;output=1st 7 bytes in statvars
; ($8A3A) contains keys
;all registers preserved
;statVars = $8A3A      ;this must be equated
;NOTE: statvars is used because it is the closet
; to the flags (iy address)

Keyin:
   di         ;disable interupts
   exx         ;use shadow register to preserve old reg
   ld hl,statvars   ;load hl to statvars
   ld bc,$0701      ;b=7 c=1
   ld de,$FFFE      ;d=$ff e=$fe
keyinlp:
   out (c),d      ;reset key port
   out (c),e      ;set to current key group
   rlc e         ;next key group
   ini         ;save key directly to hl,b-1
   jr nz,keyinlp   ;b not 0,loop
   exx         ;restore registers
;   ei         ;enable interupts (remove semicolon to do)
   ret         ;return
It'll read the entire keyport for you. If you only need to check a couple groups you could optimize it to just read those (for example, reading 2 through 5).
JamesV wrote:
Cool! If the number keys are used in more than one place, then it might be more efficient to switch the detection around, eg:

1. Check the 2nd key row for [1], [4] or [7]. If one is pressed, check the 5th row for [+] or [*] and do the required action (no action for [+] if [7] was pressed).
2. Same for the 3rd key row scanning for [2], [5] or [8].
3. Same for the 4th key row scanning for [3], [6] or [9].

I think the code will be more or less the same size either way though, as both ways you're scanning for 18 possible key combinations (only 13 of which will actually perform an action).


Which I would do. However, I might try to associate some effect with pressing the + or * key, like a GUI that confirms you are entering speed adjustment mode. If I don't do that, then yes, I'll reverse the two Smile
ACagliano wrote:
Which I would do. However, I might try to associate some effect with pressing the + or * key, like a GUI that confirms you are entering speed adjustment mode. If I don't do that, then yes, I'll reverse the two Smile
Ah yes cool, sounds great!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement