[[INP]] returns a value from a computer register or port values at a specified physical address. {{PageSyntax}} : {{Parameter|i}} = [[INP]]({{Parameter|address}}) * '''QB64 has limited access to registers. VGA memory and registers are emulated.''' * Address can be a decimal or hexadecimal [[INTEGER]] value. * [[INP]] reads directly from a register or port address. * It does not require a [[DEF SEG]] memory segment address like [[PEEK]] or [[POKE]] do. * Reads color port intensity settings after {{InlineCode}}[[OUT]] &H3C7, attribute{{InlineCodeEnd}} sets the starting attribute read mode. {{PageExamples}} ''Example 1:'' Reading the current RGB color settings used in a bitmap to an array. {{CodeStart}} '' '' SCREEN 12 {{Cl|DIM}} Colors%(47) {{Cl|OUT}} &H3C7, 0 ' set color port for INP reads at attribute 0 to start {{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 47 Colors%(i) = {{Cl|INP}}(&H3C9) ' moves to next color attribute every 3 loops {{Cl|NEXT}} '' '' {{CodeEnd}} ''Example 2:'' Reading the keyboard Scan Codes as an alternative to [[INKEY$]] {{CodeStart}} '' '' {{Cl|DO}}: {{Cl|SLEEP}} scancode% = {{Cl|INP}}(&H60) a$ = {{Cl|INKEY$}} ' clears keyboard buffer {{Cl|PRINT}} scancode%; {{Cl|LOOP}} {{Cl|UNTIL}} scancode% = 1 ' [ESC] keypress exit '' '' {{CodeEnd}} ''Example 3:'' A simple ping pong game using an array function to read multiple keys for two players. {{CodeStart}} '' '' {{Cl|DEFINT}} A-Z {{Cl|SCREEN}} 12 {{Cl|DIM}} ball%(100) ' Set aside enough space to hold the ball sprite {{Cl|CIRCLE}} (4, 3), 4, 4 {{Cl|PAINT}} (4, 3), 12, 4 ' Draw a filled circle and fill for ball {{Cl|GET (graphics statement)|GET}} (0, 0)-(8, 7), ball%(0) ' Get the sprite into the Ball% array begin: xmin = 10: ymin = 10 xmax = 630: ymax = 470 x = 25: y = 25 dx = 1: dy = 1 LTpos = 50: RTpos = 50 DO: {{Cl|_LIMIT}} 100 'adjust higher for faster {{Cl|CLS}} {{Cl|IF...THEN|IF}} ScanKey%(17) {{Cl|THEN}} LTpos = LTpos - 1 {{Cl|IF...THEN|IF}} ScanKey%(31) {{Cl|THEN}} LTpos = LTpos + 1 {{Cl|IF...THEN|IF}} ScanKey%(72) {{Cl|THEN}} RTpos = RTpos - 1 {{Cl|IF...THEN|IF}} ScanKey%(80) {{Cl|THEN}} RTpos = RTpos + 1 {{Cl|PRINT}} "Player 1 : "; ponescore; " Player 2 : "; ptwoscore {{Cl|IF...THEN|IF}} x > xmax - 15 {{Cl|AND (boolean)|AND}} y >= RTpos {{Cl|AND (boolean)|AND}} y <= RTpos + 100 {{Cl|THEN}} dx = -1 {{Cl|ELSEIF}} x > xmax {{Cl|THEN}} ponescore = ponescore + 1 {{Cl|GOSUB}} begin {{Cl|END IF}} {{Cl|IF...THEN|IF}} x < xmin + 15 {{Cl|AND (boolean)|AND}} y >= LTpos {{Cl|AND (boolean)|AND}} y <= LTpos + 100 {{Cl|THEN}} dx = 1 {{Cl|ELSEIF}} x < xmin {{Cl|THEN}} ptwoscore = ptwoscore + 1 {{Cl|GOSUB}} begin {{Cl|END IF}} {{Cl|IF...THEN|IF}} y > ymax - 5 {{Cl|THEN}} dy = -1 {{Cl|IF...THEN|IF}} y < ymin + 5 {{Cl|THEN}} dy = 1 ' Display the sprite elsewhere on the screen x = x + dx y = y + dy {{Cl|PUT (graphics statement)|PUT}}(x, y), ball%(0) {{Cl|LINE}} (20, LTpos)-(20, LTpos + 100) {{Cl|LINE}} (620, RTpos)-(620, RTpos + 100) {{Cl|_DISPLAY}} 'shows completed screen every call {{Cl|LOOP}} {{Cl|UNTIL}} ScanKey%(1) {{Cl|END}} {{Cl|FUNCTION}} ScanKey% (scancode%) {{Cl|STATIC}} Ready%, keyflags%() {{Cl|IF...THEN|IF}} {{Cl|NOT}} Ready% {{Cl|THEN}} {{Cl|REDIM}} keyflags%(0 {{Cl|TO}} 127): Ready% = -1 i% = {{Cl|INP}}({{Cl|&H}}60) 'read keyboard states {{Cl|IF...THEN|IF}} (i% {{Cl|AND (boolean)|AND}} 128) {{Cl|THEN}} keyflags%(i% {{Cl|XOR (boolean)|XOR}} 128) = 0 {{Cl|IF...THEN|IF}} (i% {{Cl|AND (boolean)|AND}} 128) = 0 {{Cl|THEN}} keyflags%(i%) = -1 K$ = {{Cl|INKEY$}} ScanKey% = keyflags%(scancode%) {{Cl|END FUNCTION}} '' '' {{CodeEnd}} : ''Note:'' [[_KEYDOWN]] can be used to read multiple keys simultaneously and is the '''recommended practice'''. {{PageSeeAlso}} * [[OUT]] {{text|(write to register)}}, [[PEEK]] {{text|(read memory)}} * [[INKEY$]], [[_KEYHIT]], [[_KEYDOWN]] * [[Bitmaps]], [[Scancodes]] {{text|(keyboard)}} * [[Port Access Libraries]] {{text|(COM or LPT registers)}} ===External Links=== * [http://en.wikipedia.org/wiki/Input/output_base_address#Common_I.2FO_base_address_device_assignments_in_IBM_PC_compatible_computers PC I/O base address device assignments] {{PageNavigation}}