Author Topic: Reading Keyboard/Mouse Input  (Read 5863 times)

Coterabeth

  • Newbie
  • *
  • Posts: 4
Reading Keyboard/Mouse Input
« on: January 27, 2013, 05:26:44 pm »
Hello everyone!  I was wondering if anyone would know a good way to read when keys are pressed on the keyboard or mouse (as in a hotkey), so that for instance, while I am holding left-CTRL, I could make my mouse repeatedly perform right-clicks using the DigiMouse library.


Something like this pseudo-code:


while(hotkey is pressed)
{
   perform action ;
}


Thank you very much for your help!

RussNelson

  • Newbie
  • *
  • Posts: 23
Re: Reading Keyboard/Mouse Input
« Reply #1 on: January 27, 2013, 05:51:21 pm »
I'm doing something like that, but not with a DigiSpark. I'm using a Teensy to connect to a PS/2 mouse. It reads the mouse buttons and movement, and passes them on to the computer unless a button on the Teensy is pressed, in which case the mouse button presses are discarded and turned into a keystroke. I don't know if a DigiSpark is capable of reading serial off one device while talking via USB to the computer.


semicolo

  • Full Member
  • ***
  • Posts: 137
Re: Reading Keyboard/Mouse Input
« Reply #2 on: January 28, 2013, 06:13:45 am »
The problem is having the digispark know when you're pushing keys, what about connecting a push button to the digispark? it'd be a lot easier that way.

Coterabeth

  • Newbie
  • *
  • Posts: 4
Re: Reading Keyboard/Mouse Input
« Reply #3 on: January 28, 2013, 07:43:24 am »
That would be a lot easier.   Thank you for the suggestion, I'll try it out!

duckythescientist

  • Newbie
  • *
  • Posts: 27
Re: Reading Keyboard/Mouse Input
« Reply #4 on: January 28, 2013, 10:43:39 am »
You'd be much better off with a button wired to the Digispark. To do what you originally thought, you would need to rewrite the USB libraries so the Digispark enumerates as a combined keyboard and mouse (not all that difficult) then implement the HID protocol to get special keys like capslock (more difficult).


As a hint for asking questions on forums, make it more obvious what your end goal is instead of asking how to accomplish the method you have thought of to accomplish your goal. Like for this, people could get stuck on working out HID code instead of just suggesting an electrically connected pushbutton. Say that you need an idea for simply triggering rapid mouse clicks. It was actually just recently that I read an article on how to ask questions for forums where I saw this hint. Source: [size=78%]http://www.catb.org/esr/faqs/smart-questions.html[/size][size=78%] [/size]

Coterabeth

  • Newbie
  • *
  • Posts: 4
Re: Reading Keyboard/Mouse Input
« Reply #5 on: January 29, 2013, 06:13:18 pm »
Thank you for the information. I'll be sure to keep that in mind for next time.  :)