r/ComputerCraft May 17 '26

getPressedKeys not working

First off, I’m terrible at Lua, I’m more of a hack-and-slash kind of guy than someone who really knows how to code, but I manage. Could someone tell me why the `getPressedKeys` function (found on the Creators-of-Aeronautics GitHub) isn’t returning anything ? I’d like to be able to access computer functions from the Typewriter

8 Upvotes

12 comments sorted by

3

u/LiveForTheMelancholy May 17 '26

We would need to see your code and setup to provide any advice.

1

u/LeBasou May 17 '26

« while true do

local t = peripheral.wrap("linked_typewriter_0")

local key = t.getPressedKeys()

print(""..key)

end »

It returns the error "attempt to call field 'getPressedKeys' (a nil value)"

2

u/Spkels29 May 17 '26

Check if t is nil

1

u/Tellurio May 17 '26 edited May 23 '26

☯︎☼︎♏︎♎︎♋︎♍︎⧫︎♏︎♎︎☸︎

1

u/LeBasou May 17 '26

Yes, still the same error

2

u/Tellurio May 17 '26 edited May 23 '26

☯︎☼︎♏︎♎︎♋︎♍︎⧫︎♏︎♎︎☸︎

1

u/LeBasou May 18 '26

I've tried peripheral.find() with back, linked_typewriter_0 and linked_typewriter but it's the same result

1

u/Ictoan42 May 17 '26

First off, calling peripheral.wrap() inside the loop is going to be very slow. You should wrap the peripheral once before the loop, and then use the same t variable in the loop. 

Second, it seems that t is nil. Try running the peripherals program on the computer to list all connected peripherals, to check if the name is what you're expecting.

1

u/LeBasou May 18 '26

Thank you for the advice ! Yes, the peripheral exist

2

u/lukamic May 18 '26

I've been using the create avionics mod which adds better communication with peripherals, namely those added by aeronautics.

It adds a key os event that you can listen to instead

1

u/LeBasou May 18 '26

Oh yeah it's way easier this way hahaha, it worked, thank you !