Hi guys! I'm new here and this is my first post.

I am currently working on a way to create a keystroke logger program of sorts, to be used in a hospital neonatal intensive care unit. It will be used in a project to look for ways to identify problems shortly after birth in newborn infants. (I was approached to create this program as I am the only one here with any programming experience, and I kinda put my foot in my mouth and said yes! D'oh!) While I have dabbled with C programming about 15 years ago (in DOS) and have some current familiarity with Excel-based VBA scripting, I have absolutely no experience with coding from scratch in Visual Basic (I'm a neurobiologist, not a programmer).

This program (I am using VB 2010 Express) is going to be used to record user-defined time-stamped events (such as "Movement", "Cough", "Cry"). A keyboard attached by the newborn's bassinet will be connected to a laptop which runs the program. The reason for time-stamping (in seconds) is so the events can be synced with video and other physiological recordings.

An example of a very simplified file would be something like this (an actual file would be longer, of course)

0 start
90 cough
260 movement
510 cry
785 stop


Right now, using sample code on the net, I've gotten a program that reads keyboard entries directly into a textbox on the main program.

Code:
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort

    Private Sub Timer1_Tick() Handles Timer1.Tick
        Dim keyResult As Integer

        Dim chrKey As String

        Dim i As Integer

        For i = 2 To 90

            keyResult = 0

            keyResult = GetAsyncKeyState(i)

            If keyResult = -32767 Then

                chrKey = Chr(i)

                MsgBox(chrKey)

                Exit For

            End If

        Next i
    End Sub
I understand how this code works, but can't seem to find anything on getting time-stamped data into it, and displaying each entered character on a new line. Also, currently, all keystrokes are recorded so backspace deletes stuff, which obviously is not good.

Things I will have to add:

1. Allow only specific keystrokes to be recorded.
2. Each keystroke should be recorded as a phrase (for example, pressing Q might be recorded as "movement". W might be "cough". E might be "cry". etc etc.)
3. Display of each event preceded by a time stamp (in seconds) from when the "Start" button was clicked.
4. "Start" button has to switch to display "Stop" once recording begins, with pressing "Stop" ending the recording. "Stop" button switches to display "Start" once recording is stopped.
5. All events (and time-stamps) will have to be written into a plain text file (i.e. eventfile1.log) and saved somewhere. I have no idea if this can be done during recording, or would have to be done at the end after hitting "Stop".
6. Pressing "Start" again clears everything and begins recording in a new file.

I have been looking up sample code online, and I realise this program is similar in a way to a keylogger. However, typing "keylogger" into google brings up some websites I'm not sure I ought to be visiting! Does anyone know of any safe sites with good sample code that might be useful? Is everything that I hope to accomplish even possible in Visual Basic? (I hope so!)

If anyone has any pointers on how to go about writing this program, they would be most appreciated! Thank you!