-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some fixes, examples created & README.md update
- Loading branch information
Showing
5 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters