Author Topic: Send Key event  (Read 4844 times)

0 Members and 1 Guest are viewing this topic.

Offline CiriousJoker

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +1/-0
    • View Profile
Send Key event
« on: April 09, 2014, 01:52:14 pm »
I wonder how i can use keyevents (Im just starting coding and wanna learn from examples, i know how to code c++ a little)


Specifically i want to let my programm do an overlay, wait for userinput and send it to the os while being active.
I wanted to make an Overlay so i can activate my Code with a button or a mouseclick.
Something like the nClock Clock overlay but with more user interactions.


~

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: Send Key event
« Reply #1 on: April 09, 2014, 02:38:32 pm »
From what you said I assume you are coding in C++ for Ndless ? You didn't make that quite clear.

Offline CiriousJoker

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +1/-0
    • View Profile
Re: Send Key event
« Reply #2 on: April 09, 2014, 03:08:03 pm »
Yes im coding in c/c++ and i found the function(?) send_key_event from libndls.h
Does anyone know how to use it?

Offline Legimet

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +29/-0
    • View Profile
Re: Send Key event
« Reply #3 on: April 10, 2014, 12:04:11 pm »
Look for it in os.h. You'll have to create an s_ns_event struct. The last argument passed to the function is unknown, so I guess you'll have to experiment with it a bit.

Offline CiriousJoker

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +1/-0
    • View Profile
Re: Send Key event
« Reply #4 on: April 10, 2014, 12:40:55 pm »
Don't think im good at coding...


I found this line in os.h

_SYSCALL4(void, send_key_event, struct s_ns_event* /* eventbuf */, unsigned short /* keycode_asciicode */, BOOL /* is_key_up */, BOOL /* unknown */)


now my questions:


I wanted to make something like a notepad (Like the Scratchpad just with notes accessible by ctrl+return key(not enter, return). Is there a better way to do that? from what i noticed other ndless programs are paused when i activate my overlay (via setPixel(...)). Does setPixel block the os or my whole program? For example nClock has a little overlay that shows the time. The overlay is updated every second. In the code i found something that looks like a hook. To make an overlay, do i have to manipulate the os?



what does _SYSCALL4(...) do?
How do i use it (example code?)?

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: Send Key event
« Reply #5 on: April 10, 2014, 01:18:58 pm »
It's a bit easier to understand (but still not very clear) in the documentation at http://hackspire.unsads.com/wiki/index.php/Libndls#Keyboard than in os.h. _SYSCALL4(...) is a macro to define a syscall with four arguments.

To make a program that opens when you press ctrl+return you have to use a hook like nClock does, yes.

Offline CiriousJoker

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +1/-0
    • View Profile
Re: Send Key event
« Reply #6 on: April 10, 2014, 04:03:03 pm »
Ok, is hooking easy? Is there any example?
I noticed that (in 3 different "examples") there are some "parts" which are almost in every hook example (i dont understand them anyway)

HOOK_INSTALL();
HOOK_ADDR
HOOK_VALUE

HOOK_DEFINE
(Is used in every example but the function is defined, so its not a real included function?)
HOOK_RESTORE_RETURN();
HOOK_SAVED_REGS();


In nClock the hook seems to be easier:

Code: [Select]
static const int hook_addrs[] = {0x100B66C8, 0x100B6988,  // Clickpad / Touchpad 3.1
                                 0x100EAAAC, 0x100EADC4,  // CX 3.1
                                 0x100E72CC, 0x100E75E4,  // CM 3.1
                                 0x101122b8, 0x100eb288,  // Clickpad / Touchpad 3.6
                                 0x10111cfc, 0x1011201C}; // CX 3.6


#define HOOK_ADDR (nl_osvalue((int*)hook_addrs, sizeof(hook_addrs)/sizeof(hook_addrs[0])))


static const int hook_values[] = {0xe92d47f0, 0xe92d47f0,
                                  0xE59F1030, 0xE59F1030,
                                  0xE59F1030, 0xE59F1030,
                                  0xE59F1030, 0xE59F1030,
                                  0xE59F1030, 0xE59F1030};


#define HOOK_VALUE (nl_osvalue((int*)hook_values, sizeof(hook_values)/sizeof(hook_values[0])))


HOOK_DEFINE(hook_nclock) {
    if(!*noMiniClock)
        mini_nclock(1);
    HOOK_RESTORE_RETURN(hook_nclock);
}

But i wonder what the hook_addr[] and hook_values[] is.
Is a hook_addr a ram address and hook_value is the value?


What do these lines mean?
#define HOOK_ADDR (...);
#define HOOK_VALUE(...);

What line exactly does "install" the hook (Or is it a combination of everything?)?


I know these are a lot of questions but i'd be really happy to find some answers :)