Skip to content

Use the librarys in built SendKeyPress function #36

Open

Description

@sparky3387

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;
   }
}

Activity

  1. nforro commented on Aug 22, 2019

    @nforro
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions