vbe0201 / 3DS.py

Python on your Nintendo 3DS
Apache License 2.0
134 stars 7 forks source link

_ctru inputs not working #13

Closed Bluebotlabz closed 3 years ago

Bluebotlabz commented 3 years ago

I was attempting to run the code in #11 on my 3DS:

import _ctru

# Bitmasks of all the keys.
A = 1 << 0
B = 1 << 1

while True:
    input = _ctru.hid_keys_down()
    if input & A == A:
        print("A pressed!")

However, when run the code outputs the following error:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import _ctru
ModuleNotFoundError: No module named '_ctru'

Does the _ctru module need to be built separately or am I doing something wrong?

builtinhold commented 3 years ago

I am getting the same, but only with the binary from github. There are a couple of other binaries around in the discord channels, and with those the same code just produces a black screen and hangs the 3ds.

Bluebotlabz commented 3 years ago

Yes, using the Discord binary stops the error, but _ctru does not work anyway. Perhaps the _ctru library has to be compiled separately?

EDIT: It would appear that other people are having the same problem on the discord channel.

builtinhold commented 3 years ago

The stable version in github cannot load the module correctly. But it does work with the latest versions of 3DS.py that are available through the Discord. The code in the example is missing a call to hid_scan_input(). Discussion can be seen in the Discord with a working example.

Bluebotlabz commented 3 years ago

It works, thank you!

Updated exmaple code:

import sys
import _ctru 

BTN_A = 1 << 0
BTN_B = 1 << 1

def Test():

  print(f"Entering main loop", flush=True) 
  while True:

    _ctru.hid_scan_input()

    key_mask = _ctru.hid_keys_down()

    if key_mask & BTN_A:
      print(f"Button A was pressed", flush=True)
      break
    if key_mask & BTN_B:
      print(f"Button B was pressed", flush=True)
      break

def main():

  Test()
  print("Bye bye!")

if __name__== "__main__":
  main()

3DS.py.zip This is the current latest Discord build that I could find if anyone needs it