Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!tcdcs!swift.cs.tcd.ie!vax1.tcd.ie!smcgerty From: smcgerty@vax1.tcd.ie Newsgroups: comp.sys.amiga.programmer Subject: keypress scanning Message-ID: <1991Feb9.114958.7734@vax1.tcd.ie> Date: 9 Feb 91 11:49:58 GMT References: <787@cbmger.UUCP> <1991Feb2.000213.11161@athena.mit.edu> Distribution: comp Organization: Trinity College Dublin Lines: 54 In article <1991Feb2.000213.11161@athena.mit.edu>, cadill@athena.mit.edu (Christopher J Carrillo) writes: >> >>In article cadill@athena.mit.edu (Christopher J Carrillo) writes: >>>I would like to know how to write a C program which monitors the keyboard and >>>writes a record of every keypress to a file. >> >>There are some examples on the Fish disks. From my brain, there is >>1. Journal, and 2. a pair of programs Report/??? (sorry, forgot the name). > > Do you mean that on Fred Fish disk number 1 there is a program named "Journal" > and on Fred Fish disk number 2 there are two programs in a directory called > "Report" ? > I'm sorry, I just didn't understand what you meant. I havn't a clue about the Fish disks, but if you want to detect what keys are being pressed at any instant, then there is a cheap and dirty way of doing it using the hardware; someone else can work out a way of outputting them to a file... (preferably not using the following...) WARNING: I DON'T KNOW IF THIS WILL WORK ON ALL AMIGAS. (I use an A500) I have discovered that the currently depressed key is held at $bfec01 Just peek this value, XOR it with 255 ($FF) and rotate it left once. The resulting number corresponds with the key value table in the Amiga Hardware Reference Manual: eg F1-F10 = $50-$59 I'll give a quick example in M68000 assembly and not in C, as it look ugly in C! move.b $bfec01,d0 eor.b #$ff,d0 ror.b #1,d0 cmp.b #$50,d0 bne NOT_F1 ; Do F1 stuff NOT_F1 cmp.b .... I dunno if this helps anyone. (It may be ugly, but its a neatish way of checking the keys if you have turned off multitasking.) I haven't actually used this method for anything (I'm an Intui/C type programmer by default) but I have come across a few people who like doing Hardware level programming, but couldn't detect the keyboard, so this looked as good an opening as I was likely to get to tell the world.. REMEMBER: I'm pretty certain this is the sort of thing C= hate to see, so don't come crying to anyone if it doesn't work on your machine. Mail me if you have any thoughts on the good/bad styles of programming the amiga, or if you have any other little 'twiks'... ---------------------------------------------------------------------------- | / T | / Stephen John McGerty | "I could be wrong" Amiga // | | / | |/ smcgerty@vax1.tcd.ie (C.Sci.) | Me. \\// | |__________________________________________|_______________________________|