Skip to content

Commit

Permalink
Some fixes, examples created & README.md update
Browse files Browse the repository at this point in the history
  • Loading branch information
broelik committed Aug 24, 2020
1 parent cee17b2 commit 1f60a48
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 28 deletions.
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
# jphp-nativehook-ext
NativeHook for jphp

NativeHook for jphp.

## Install
## Installation
```
jppm add nativehook
```
## Examples
```php
use nativehook\NativeHook;
use nativehook\NativeMouseEvent;
use nativehook\NativeKeyEvent;
use nativehook\NativeMouseWheelEvent;

$hook = new NativeHook;
// mouseUp, mouseDown, mouseClick, mouseMove or mouseDragged
$hook->on('mouseDown', function(NativeMouseEvent $e){
echo "Mouse pressed on {$e->x},{$e->y}\n";
});
// keyUp, keyDown or keyPress
$hook->on('keyUp', function(NativeKeyEvent $e){
echo "Key {$e->key} is released\n";
});
$hook->on('mouseWheel', function(NativeMouseWheelEvent $e){
echo "Mouse wheel\n";
});
You can find an example in the [directory](examples/). of the same name

$hook->start();
...
$hook->stop();
```
## Bundle for develnext
[download](https://github.com/jphp-group/jphp-nativehook-ext/releases/download/1.0.6/nativehook.dnbundle)
See Releases tab

## API Documentation
[api-docs](api-docs/).
[api-docs](api-docs/)
12 changes: 12 additions & 0 deletions examples/package.php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: examples
version: 1.0.0
deps:
jphp-core: '*'
jphp-zend-ext: '*'
nativehook: '*'
plugins:
- App
sources:
- src
includes:
- index.php
78 changes: 78 additions & 0 deletions examples/src/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

use nativehook\GlobalScreen;
use nativehook\keyboard\NativeKeyEvent;
use nativehook\keyboard\NativeKeyListener;
use nativehook\mouse\NativeMouseEvent;
use nativehook\mouse\NativeMouseListener;
use nativehook\mouse\NativeMouseMotionListener;
use nativehook\mouse\NativeMouseWheelEvent;
use nativehook\mouse\NativeMouseWheelListener;
use php\lang\System;

class EventListener implements NativeKeyListener, NativeMouseListener, NativeMouseMotionListener, NativeMouseWheelListener{
public function nativeKeyReleased(NativeKeyEvent $event){
var_dump(__FUNCTION__."- {$event->keyText}");
}

public function nativeKeyPressed(NativeKeyEvent $event){
var_dump(__FUNCTION__."- {$event->keyText}");
}

public function nativeKeyTyped(NativeKeyEvent $event){
var_dump(__FUNCTION__."- {$event->keyChar}");
}

public function nativeMouseClicked(NativeMouseEvent $event){
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
}

public function nativeMousePressed(NativeMouseEvent $event){
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
}

public function nativeMouseReleased(NativeMouseEvent $event){
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
}

public function nativeMouseMoved(NativeMouseEvent $event){
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
}

public function nativeMouseDragged(NativeMouseEvent $event){
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
}

public function nativeMouseWheelMoved(NativeMouseWheelEvent $event){
var_dump(__FUNCTION__." - scrollType: {$event->scrollType}, scrollAmount: {$event->scrollAmount}, wheelRotation: {$event->wheelRotation}");
}
}

class ExitListener implements NativeKeyListener{
public function nativeKeyPressed(NativeKeyEvent $event){
if($event->keyText == 'Escape'){
GlobalScreen::unregisterNativeHook();
System::halt(0);
}
}

public function nativeKeyReleased(NativeKeyEvent $event){

}

public function nativeKeyTyped(NativeKeyEvent $event){

}
}

$listener = new EventListener();
GlobalScreen::addNativeKeyListener($listener);
GlobalScreen::addNativeMouseListener($listener);
GlobalScreen::addNativeMouseMotionListener($listener);
GlobalScreen::addNativeMouseWheelListener($listener);

GlobalScreen::addNativeKeyListener(new ExitListener());

GlobalScreen::registerNativeHook();

echo "Press Escape to exit\n";
4 changes: 4 additions & 0 deletions package.php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ config:
- /.git/**
- /examples/**
- /package.hub.yml
- /bundle/**
- /src-bundle/**
- /README.MD
- /.gitignore


gradle:
Expand Down
2 changes: 1 addition & 1 deletion sdk/nativehook/keyboard/NativeKeyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface NativeKeyListener{
* @param NativeKeyEvent $event
* @return void
*/
public function nativeKeyPressed($event);
public function nativeKeyPressed(NativeKeyEvent $event);
/**
* @param NativeKeyEvent $event
* @return void
Expand Down

0 comments on commit 1f60a48

Please sign in to comment.