Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the librarys in built SendKeyPress function #36

Open
sparky3387 opened this issue Aug 21, 2019 · 1 comment
Open

Use the librarys in built SendKeyPress function #36

sparky3387 opened this issue Aug 21, 2019 · 1 comment

Comments

@sparky3387
Copy link

Im trying to modify your library so it supports the inbuilt sendkeypress (and sendkeyrelease), but am having issues, here is what I have come up with so far (it appears to work, but nothing happens and it crashes with a stack smash):

static PyObject * Device_send_key_press(Device * self, PyObject * args) {
   unsigned char keycode;
   bool bWait;
   cec_user_control_code keypress;
   if( PyArg_ParseTuple(args, "bp:sendkeypress", &keycode,
         &bWait) ) {
      keypress = (cec_user_control_code) keycode;
      bool success;
      Py_BEGIN_ALLOW_THREADS
      cec_logical_address destination = self->addr;
      success = adapter->SendKeypress(destination, keypress, bWait);
      Py_END_ALLOW_THREADS
      if( success ) {
         Py_RETURN_TRUE;
      } else {
         Py_RETURN_FALSE;
      }
   } else {
      return NULL;
   }
}

@nforro
Copy link
Collaborator

nforro commented Aug 22, 2019

I don't see anything obviously wrong with your code, if you want help with the crash, you have to provide more info, ideally complete backtrace, and also the python code you are using.

BTW, you can do the same with this code:

opcode = cec.CEC_OPCODE_USER_CONTROL_PRESSED
parameters = bytes([keycode])
device.transmit(opcode, parameters)

You will lose the bWait argument, but in case of CEC_OPCODE_USER_CONTROL_PRESSED it's noop anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants