1. keyboard help
- Posted by illusioneye <dkoter at SPRINT.CA> May 11, 1999
- 691 views
------=_NextPart_000_0004_01BE9B7F.BA9F3360 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I would like to know how to put a sequence of keys into the keyboard = buffer (memory) For instance if I want to put the phrase "Hello, my name is Jhon" in the = buffer when I'm going to get the keys with get_key() all the characters = will already be there. Thanks for your help ------=_NextPart_000_0004_01BE9B7F.BA9F3360 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD> <META content=3Dtext/html;charset=3Diso-8859-1 = http-equiv=3DContent-Type> <META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT color=3D#000000 size=3D2>I would like to know how to put a = sequence of=20 keys into the keyboard buffer (memory)</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 size=3D2>For instance if I want to put the = phrase=20 "Hello, my name is Jhon" in the buffer </FONT><FONT = color=3D#000000=20 size=3D2>when I'm going to get the keys with get_key() all the = characters will=20 already be there.</FONT></DIV> <DIV><FONT color=3D#000000 size=3D2></FONT> </DIV> <DIV><FONT color=3D#000000 = ------=_NextPart_000_0004_01BE9B7F.BA9F3360--
2. Re: keyboard help
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> May 11, 1999
- 639 views
>I would like to know how to put a sequence of keys into the keyboard buffer >(memory) >For instance if I want to put the phrase "Hello, my name is Jhon" in the buffer >when I'm going to get the keys with get_key() all the characters will >already be there. --- The code below, put it in an include or just in your program and then: -- use get_key () to get a new key -- use put_key (key) or put_key ({key, key, key}) to put a new key -- That's it, you're welcome ... -- Ralf N. sequence buffer integer bindex function old_get_key () return get_key () end function function get_key () integer char if length(buffer) then char = buffer[length(buffer)] buffer = buffer[1..length(buffer)-1] return char else return old_get_key () end if end function procedure put_key (object x) buffer = x & buffer end procedure
3. Re: keyboard help
- Posted by David Cuny <dcuny at LANSET.COM> May 10, 1999
- 637 views
- Last edited May 11, 1999
"IllusionEye" wrote: > I would like to know how to put a sequence of keys into the keyboard buffer (memory). It's been a long time since I've worked with this, so I'm a bit fuzzy on this... The keyboard buffer is a circular queue. The addresses are: KEY_BUFFER = 1054 FIRST_INDEX = 1050 LAST_INDEX = 1052 KEY_BUFFER is the address of the circular buffer. FIRST_INDEX is the index (offset) to the first key in the buffer LAST_INDEX is the index (offset) to the last key in the buffer When FIRST_INDEX = LAST_INDEX, the buffer is empty. You can zap the buffer by setting them to the same value: poke( FIRST_INDEX, peek( LAST_INDEX ) ) I *think* the buffer can hold up to 16 characters. Each character is stored as two bytes - the scan key code and the key code. Notice the "- 29" and "- 30"; I hacked at the values until the worked. scanCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 29 ) keyCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) - 30 ) So the buffer is (I think) 32 bytes long in total. Since it's circular, don't forget to wrap your characters. Obviously, when the LAST_INDEX is advanced past the end of the buffer, it needs to wrap around to the beginning again. If the LAST_INDEX is advanced onto the FIRST_INDEX, the buffer will be overwritten. Ick. -- David Cuny
4. Re: keyboard help
- Posted by Bernie Ryan <bwryan at PCOM.NET> May 13, 1999
- 674 views
I think your peek and poke are interchanged. Also your peeking and poking addresses and not bytes.
5. Re: keyboard help
- Posted by "Cuny, David" <David.Cuny at DSS.CA.GOV> May 13, 1999
- 689 views
Bernie Ryan wrote: > I think your peek and poke are interchanged. You are correct; my code example shows how to read the buffer, not how to write it. I've never actually tried writing to the buffer. Well, I've never successfully written to it, anyway. Once I figured out that it was circular and fairly small, I figured I had better things to do in life than to mess with it. > Also your peeking and poking addresses and not bytes. Keep in mind that FIRST_INDEX *contains* a value. So to find the scanCode for the next character in the buffer, you need to get the value out of FIRST_INDEX and add it to KEY_BUFFER. As I look at my example, it looks the address that I use for KEY_BUFFER is actually off by 29 bytes. That is, the actual address of KEY_BUFFER is probably: KEY_BUFFER = 1083 so the examples would then read: scanCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) ) keyCode = peek( KEY_BUFFER + peek( FIRST_INDEX ) + 1 ) Or perhaps more clearly: -- get the position of the first char in the buffer index = peek( FIRST_INDEX ) -- look in the buffer for the scan code scanCode = peek( KEY_BUFFER + index ) -- look in the buffer at the next byte for the key code keyCode = peek( KEY_BUFFER + index + 1 ) I'm not even going to hazard trying to write an example that updates the buffers. Among other issues, you have to turn off the interrupts. Otherwise, if the user presses a key while your routine is running, *bad* things will happen when the interrupt kicks in and updated the buffer that you were messing with. All in all, I think that Ralf's solution was the cleanest. -- David Cuny
6. keyboard help
- Posted by Michael Packard <lgp at EXO.COM> Dec 08, 1996
- 687 views
hi. Anybody know how to (easliy) ready the keyboard directly? I need to know what keys are currenly being help down, not just the last one pressed. If I'm holding down the "turn" key and then press and hold the "fire" I want to continue turning while firing too, until I release the "turn" key. How do I do it? Michael Packard Lord Generic Productions lgp at exo.com http://exo.com/~lgp A Crash Course in Game Design and Production http://exo.com/~lgp/euphoria
7. Re: keyboard help
- Posted by David Gay <moggie at INTERLOG.COM> Dec 08, 1996
- 694 views
At 12:52 AM 12/8/96 -0800, you wrote: >---------------------- Information from the mail header ----------------------- >Sender: Euphoria Programming for MS-DOS <EUPHORIA at >MIAMIU.ACS.MUOHIO.EDU> >Poster: Michael Packard <lgp at EXO.COM> >Subject: keyboard help >------------------------------------------------------------------------------- > >hi. Anybody know how to (easliy) ready the keyboard directly? I need to >know what keys are currenly being help down, not just the last one >pressed. If I'm holding down the "turn" key and then press and hold the >"fire" I want to continue turning while firing too, until I release the >"turn" key. Hi Michael :) The only other way I know is to access a DOS interrupt using an assembler call. It's been a while since I've used assembler for anything, so I don't remember it. However, I do have my DOS INT FAQ lying around somewhere on my hard drive so I can look it up for you if you desire. Thanks David
8. Re: keyboard help
- Posted by Jacques Deschenes <desja at QUEBECTEL.COM> Dec 08, 1996
- 693 views
--=====================_850082487==_ At 00:52 8-12-96 -0800, you wrote: >---------------------- Information from the mail header ----------------------- >Sender: Euphoria Programming for MS-DOS <EUPHORIA at >MIAMIU.ACS.MUOHIO.EDU> >Poster: Michael Packard <lgp at EXO.COM> >Subject: keyboard help >------------------------------------------------------------------------------- > >hi. Anybody know how to (easliy) ready the keyboard directly? I need to >know what keys are currenly being help down, not just the last one >pressed. If I'm holding down the "turn" key and then press and hold the >"fire" I want to continue turning while firing too, until I release the >"turn" key. > >How do I do it? > >Michael Packard >Lord Generic Productions >lgp at exo.com http://exo.com/~lgp >A Crash Course in Game Design and Production >http://exo.com/~lgp/euphoria > Hi Michael, Unless you're ready for system programming in assembler, just forget it. The actual keyboard interrupt service routine only track one key at a time. The keyboard send 2 codes for each key. One when the key is pushed down and one when the key is released. If you push a second key while a first one is down the ISR doesn`t remember the first one is still down. >>>> BUT there is a way around it if you are ready to change your game keys. There is 9 keys on the keyboards that are track down. You can push many of them without interfering with each other. I include gamepad.e and tstgampd.ex to show you how to transform the special keys of the keyboard in game pad. With gamepad.e you can still use alpha key but only once at a time and it's simpler to use the scan codes by calling GetScanCode() instead of get_key(). For more informaiton see note at beginning of gamepad.e file. --=====================_850082487==_ -- NAME: GAMEPAD.E -- OBJECT: use keyboard special keys as a game pad. -- CREATION DATE: Dec. 8th, 1996 -- BY: Jacques Deschenes, Baie-Comeau, Canada, e-mail:Desja at quebectel.com -- RATIONALE: the problem with using the keyboard as a game pad is that one -- can't press 2 keys at the same time, because the keyboard service routine -- only track one key. If the player hold down a key and then push a second -- key the Interrupt service routine doesn't see the first key any more. The -- player have to release it and push it again for the ISR to detect it. -- Possible solutions: -- 1) rewrite keyboard ISR. Best solution if you are system programmer. -- 2) on the keyboard there is special keys that the service routine process -- differently. Those keys are flagged has long as they are holded down. -- The player can hold down 2 or 3 of those keys without loosing tracking. -- The 9 flagged keys are: -- RIGHT SHIFT -- LEFT SHIFT -- RIGHT CONTROL -- LEFT CONTROL -- RIGHT ALT -- LEFT ALT -- CAPS LOCK -- NUM LOCK -- SCROLL LOCK -- For their position on the keyboard the first 6 are the best to use for game. -- -- This include file implement solution 2. -- Another problem arise from that solution: The key code returned by normal -- key is modified by the control and alt keys. So if the game use normal key -- like spacebar the get_key() will return different value depending if the -- player is holding down control, alt or control-alt at the same time he press -- spacebar. -- A partial solution to that problem is to read the scan code instead of the -- key code as scan codes of alpha keys are not modified by the specials keys. -- (but arrows and functions keys scan codes are modified) -- -- This include file export only 3 functions: -- GetKeyPad() which return a sequence containing the state of all specials -- keys. -- KeyPressed() return 1 if a key is pressed. -- GetScanCode() which return the scan code or normal key if one is pressed. include machine.e -- index constants to access keypad sequence returned by GetKeyPad() constant siR_SHIFT = 1, siL_SHIFT = 2, siL_CTRL = 3, siL_ALT = 4, siR_CTRL = 5, siR_ALT = 6, siSCR_LOCK = 7, siNUM_LOCK = 8, siCAP_LOCK = 9 global function GetKeyPad() -- return keyboard flags -- output register AH containt AT flags and AL containt XT flags sequence r, at, xt r = repeat(0,10) r[REG_AX] = #1200 r = dos_interrupt(#16,r) at = int_to_bits(floor(r[REG_AX]/256),8) xt = int_to_bits(remainder(r[REG_AX],256),8) return xt[1..2]&at[1..7] end function -- GetKeyPad() global function KeyPressed() -- check if a key is present in keyboard buffer sequence r r = repeat(0,10) r[REG_AX] = #1100 r = dos_interrupt(#16,r) return remainder(r[REG_FLAGS],8) < 4 -- key present if zero flag = 0 end function --KeyPressed() global function GetScanCode() sequence r if KeyPressed() then r = repeat(0,10) r[REG_AX] = #1000 r = dos_interrupt(#16,r) return floor(r[REG_AX]/256) end if return 0 end function -- GetScanCode() --=====================_850082487==_ include gamepad.e integer code,PrevCode sequence flags code = 0 PrevCode = 0 constant PadStr={"RIGHT SHIFT","LEFT SHIFT","LEFT CONTROL","LEFT ALT", "RIGHT CONTROL", "RIGHT ALT", "SCROLL LOCK", "NUM LOCK", "CAPS LOCK"} procedure ShowPad(sequence pad) position(2,1) for i = 1 to length(pad) do if pad[i] = 1 then puts(1,PadStr[i]&'\n') else puts(1," \n") end if end for end procedure clear_screen() while code != 1 do code = GetScanCode() if code and code != PrevCode then position(1,1) printf(1,"Scan code = %3d\n",{code}) PrevCode = code end if flags = GetKeyPad() ShowPad(flags) end while --=====================_850082487==_ Jacques Deschenes Baie-Comeau, Quebec Canada desja at quebectel.com --=====================_850082487==_--