Skip to content

Commit 1f60a48

Browse files
committed
Some fixes, examples created & README.md update
1 parent cee17b2 commit 1f60a48

File tree

5 files changed

+101
-28
lines changed

5 files changed

+101
-28
lines changed

README.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,15 @@
11
# jphp-nativehook-ext
2+
NativeHook for jphp
23

3-
NativeHook for jphp.
4-
5-
## Install
4+
## Installation
65
```
76
jppm add nativehook
87
```
98
## Examples
10-
```php
11-
use nativehook\NativeHook;
12-
use nativehook\NativeMouseEvent;
13-
use nativehook\NativeKeyEvent;
14-
use nativehook\NativeMouseWheelEvent;
15-
16-
$hook = new NativeHook;
17-
// mouseUp, mouseDown, mouseClick, mouseMove or mouseDragged
18-
$hook->on('mouseDown', function(NativeMouseEvent $e){
19-
echo "Mouse pressed on {$e->x},{$e->y}\n";
20-
});
21-
// keyUp, keyDown or keyPress
22-
$hook->on('keyUp', function(NativeKeyEvent $e){
23-
echo "Key {$e->key} is released\n";
24-
});
25-
$hook->on('mouseWheel', function(NativeMouseWheelEvent $e){
26-
echo "Mouse wheel\n";
27-
});
9+
You can find an example in the [directory](examples/). of the same name
2810

29-
$hook->start();
30-
...
31-
$hook->stop();
32-
```
3311
## Bundle for develnext
34-
[download](https://github.com/jphp-group/jphp-nativehook-ext/releases/download/1.0.6/nativehook.dnbundle)
12+
See Releases tab
13+
3514
## API Documentation
36-
[api-docs](api-docs/).
15+
[api-docs](api-docs/)

examples/package.php.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: examples
2+
version: 1.0.0
3+
deps:
4+
jphp-core: '*'
5+
jphp-zend-ext: '*'
6+
nativehook: '*'
7+
plugins:
8+
- App
9+
sources:
10+
- src
11+
includes:
12+
- index.php

examples/src/index.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
use nativehook\GlobalScreen;
4+
use nativehook\keyboard\NativeKeyEvent;
5+
use nativehook\keyboard\NativeKeyListener;
6+
use nativehook\mouse\NativeMouseEvent;
7+
use nativehook\mouse\NativeMouseListener;
8+
use nativehook\mouse\NativeMouseMotionListener;
9+
use nativehook\mouse\NativeMouseWheelEvent;
10+
use nativehook\mouse\NativeMouseWheelListener;
11+
use php\lang\System;
12+
13+
class EventListener implements NativeKeyListener, NativeMouseListener, NativeMouseMotionListener, NativeMouseWheelListener{
14+
public function nativeKeyReleased(NativeKeyEvent $event){
15+
var_dump(__FUNCTION__."- {$event->keyText}");
16+
}
17+
18+
public function nativeKeyPressed(NativeKeyEvent $event){
19+
var_dump(__FUNCTION__."- {$event->keyText}");
20+
}
21+
22+
public function nativeKeyTyped(NativeKeyEvent $event){
23+
var_dump(__FUNCTION__."- {$event->keyChar}");
24+
}
25+
26+
public function nativeMouseClicked(NativeMouseEvent $event){
27+
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
28+
}
29+
30+
public function nativeMousePressed(NativeMouseEvent $event){
31+
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
32+
}
33+
34+
public function nativeMouseReleased(NativeMouseEvent $event){
35+
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
36+
}
37+
38+
public function nativeMouseMoved(NativeMouseEvent $event){
39+
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
40+
}
41+
42+
public function nativeMouseDragged(NativeMouseEvent $event){
43+
var_dump(__FUNCTION__." - x: {$event->x}, y: {$event->x}, button: {$event->button}");
44+
}
45+
46+
public function nativeMouseWheelMoved(NativeMouseWheelEvent $event){
47+
var_dump(__FUNCTION__." - scrollType: {$event->scrollType}, scrollAmount: {$event->scrollAmount}, wheelRotation: {$event->wheelRotation}");
48+
}
49+
}
50+
51+
class ExitListener implements NativeKeyListener{
52+
public function nativeKeyPressed(NativeKeyEvent $event){
53+
if($event->keyText == 'Escape'){
54+
GlobalScreen::unregisterNativeHook();
55+
System::halt(0);
56+
}
57+
}
58+
59+
public function nativeKeyReleased(NativeKeyEvent $event){
60+
61+
}
62+
63+
public function nativeKeyTyped(NativeKeyEvent $event){
64+
65+
}
66+
}
67+
68+
$listener = new EventListener();
69+
GlobalScreen::addNativeKeyListener($listener);
70+
GlobalScreen::addNativeMouseListener($listener);
71+
GlobalScreen::addNativeMouseMotionListener($listener);
72+
GlobalScreen::addNativeMouseWheelListener($listener);
73+
74+
GlobalScreen::addNativeKeyListener(new ExitListener());
75+
76+
GlobalScreen::registerNativeHook();
77+
78+
echo "Press Escape to exit\n";

package.php.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ config:
2626
- /.git/**
2727
- /examples/**
2828
- /package.hub.yml
29+
- /bundle/**
30+
- /src-bundle/**
31+
- /README.MD
32+
- /.gitignore
2933

3034

3135
gradle:

sdk/nativehook/keyboard/NativeKeyListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface NativeKeyListener{
99
* @param NativeKeyEvent $event
1010
* @return void
1111
*/
12-
public function nativeKeyPressed($event);
12+
public function nativeKeyPressed(NativeKeyEvent $event);
1313
/**
1414
* @param NativeKeyEvent $event
1515
* @return void

0 commit comments

Comments
 (0)