Simple user interface for data collection

I know this is a vague question, but I was hoping to get some help. I know VBA well and was able to perform some simple tasks in python, as well as statistical programming language in R.

I want to create a simple application that allows me to capture data, some of which are captured from the keyboard. Every time there is a keystroke, I wanted to create a new record in my dataset.

In some context, consider creating a simple interface that allows me to track the location (and duration) of the puck in an NHL hockey game.

I'm not really a programmer, but I know enough to get into trouble, and I'm not sure where to start. I'm just looking for some thoughts on a very simple (non-profit) solution.

Thank you very much in advance.

EDIT: I want to capture how long the puck is in each zone. I plan to use the left / right direction keys to β€œfollow” the puck from zone to each. Every time the puck changes to a zone, I want to β€œclose” the active record and start a new one. The start and end times will allow me to calculate how long the puck has been in the zone. I also need a way to stop creating a new record for things like faceoffs, tv time outs and the end of the period. I planned to use a space. I thought that if I did it right, when I follow it, the recorded clock should match what is on the game clock found on the TV. Yes, this is a crazy idea.

+4
source share
3 answers

If you selected a Python program:

You can use the pygame package to easily capture keyboard events. The library was created for writing games, but will probably give you the functionality you are looking for with keydown / keyup events. It also handles mouse events and (since it is designed for games) has the ability to make graphics / text. The documentation is really good and it is a cross platform. A possible drawback is that you should have a β€œscreen” and it should have focus. Here is a small example:

import pygame def main(): """ Pygame Example """ pygame.init() screen = pygame.display.set_mode((200, 200)) app_running = True while app_running: # Get all key/mouse events from system. events = pygame.event.get() # Loop thru each event... for e in events: # Handle when the program is killed. if e.type == pygame.QUIT: app_running = False break # Handle key events. elif e.type == pygame.KEYDOWN: # Exit if escape is pressed. if e.key == pygame.K_ESCAPE: app_running = False # Do something when the right arrow # is pressed. elif e.key == pygame.K_RIGHT: print "right arrow pressed" # Do something when the left arrow # is pressed. elif e.key == pygame.K_LEFT: print "left arrow pressed" # and so on ... # Fill the screen to blank it. #screen.fill(mycolor) # Write someting to the screen to display. #screen.blit(some_image, some_position) # Flip to display. #screen.flip() pygame.quit() if __name__ == '__main__': main() 

If you are using a version of Windows, you can use the msvcrt library, but event handling is not as good as pygame : instead of events, you have to deal with raw keyboard output, and this is a little less intuitive. Here is a small snippet of code from Robert Gillies on ActiveState :

 import msvcrt def funkeypress(): """ Waits for the user to press any key including function keys. Returns the ascii code for the key or the scancode for the function key. """ while 1: if msvcrt.kbhit(): # Key pressed? a = ord(msvcrt.getch()) # get first byte of keyscan code if a == 0 or a == 224: # is it a function key? b = ord(msvcrt.getch()) # get next byte of key scan code x = a + (b*256) # cook it. return x # return cooked scancode else: return a # else return ascii code 
+1
source

Look at scan () for keyboard input in R. And you did not ask about mouse input, but consider locator () for this.

Put it in a loop if you want to get the result right away.

0
source

Do you need to program yourself? There is a free program called jwatcher designed to measure animal behavior in etiological studies. It looks like it will be well suited to your task.

0
source

Source: https://habr.com/ru/post/1344973/


All Articles