Skip to content

Commit cc6aafa

Browse files
committed
updated examples and JS method
1 parent d97f372 commit cc6aafa

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ desktop.right_click()
175175
desktop.middle_click()
176176
desktop.scroll(10) # Scroll by the amount. Positive for up, negative for down.
177177
desktop.mouse_move(100, 200) # Move to x, y coordinates
178+
desktop.drag((100, 100), (200, 200)) # Drag using the mouse
178179
```
179180

180181
**JavaScript**
@@ -190,6 +191,7 @@ await desktop.rightClick()
190191
await desktop.middleClick()
191192
await desktop.scroll(10) // Scroll by the amount. Positive for up, negative for down.
192193
await desktop.moveMouse(100, 200) // Move to x, y coordinates
194+
await desktop.drag([100, 100], [200, 200]) // Drag using the mouse
193195
```
194196

195197
### Keyboard control
@@ -208,7 +210,7 @@ desktop.write("Fast typing!", chunk_size=50, delay_in_ms=25) # Faster typing
208210
desktop.press("enter")
209211
desktop.press("space")
210212
desktop.press("backspace")
211-
desktop.press(["ctrl", "c"])
213+
desktop.press(["ctrl", "c"]) # Key combination
212214
```
213215

214216
**JavaScript**
@@ -226,7 +228,7 @@ await desktop.write('Fast typing!', { chunkSize: 50, delayInMs: 25 }) // Faster
226228
await desktop.press('enter')
227229
await desktop.press('space')
228230
await desktop.press('backspace')
229-
await desktop.press(['ctrl', 'c']) // Copy
231+
await desktop.press(['ctrl', 'c']) // Key combination
230232
```
231233

232234
### Screenshot
@@ -305,6 +307,26 @@ const out = await desktop.commands.run('ls -la /home/user')
305307
console.log(out)
306308
```
307309

310+
### Wait
311+
312+
**Python**
313+
314+
```python
315+
from e2b_desktop import Sandbox
316+
desktop = Sandbox()
317+
318+
desktop.wait(1000) # Wait for 1 second
319+
```
320+
321+
**JavaScript**
322+
323+
```javascript
324+
import { Sandbox } from '@e2b/desktop'
325+
326+
const desktop = await Sandbox.create()
327+
await desktop.wait(1000) // Wait for 1 second
328+
```
329+
308330
## Under the hood
309331

310332
The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.

packages/js-sdk/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ await desktop.rightClick()
105105
await desktop.middleClick()
106106
await desktop.scroll(10) // Scroll by the amount. Positive for up, negative for down.
107107
await desktop.moveMouse(100, 200) // Move to x, y coordinates
108+
await desktop.drag([100, 100], [200, 200]) // Drag using the mouse
108109
```
109110

110111
### Keyboard control
@@ -122,7 +123,7 @@ await desktop.write('Fast typing!', { chunkSize: 50, delayInMs: 25 }) // Faster
122123
await desktop.press('enter')
123124
await desktop.press('space')
124125
await desktop.press('backspace')
125-
await desktop.press('ctrl+c') // Copy
126+
await desktop.press(['ctrl', 'c']) // Key combination
126127
```
127128

128129
### Screenshot
@@ -160,6 +161,15 @@ const out = await desktop.commands.run('ls -la /home/user')
160161
console.log(out)
161162
```
162163

164+
### Wait
165+
166+
```javascript
167+
import { Sandbox } from '@e2b/desktop'
168+
169+
const desktop = await Sandbox.create()
170+
await desktop.wait(1000) // Wait for 1 second
171+
```
172+
163173
## Under the hood
164174

165175
The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.

packages/js-sdk/src/sandbox.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ export class Sandbox extends SandboxBase {
386386
* @param from - The starting position.
387387
* @param to - The ending position.
388388
*/
389-
async drag(from: CursorPosition, to: CursorPosition): Promise<void> {
389+
async drag([x1, y1]: [number, number], [x2, y2]: [number, number]): Promise<void> {
390390
await this.commands.run(
391-
`xdotool mousemove ${from.x} ${from.y} && xdotool mousedown 1 && xdotool mousemove ${to.x} ${to.y} && xdotool mouseup 1`,
391+
`xdotool mousemove ${x1} ${y1} && xdotool mousedown 1 && xdotool mousemove ${x2} ${y2} && xdotool mouseup 1`,
392392
{ envs: { DISPLAY: this.display } }
393393
);
394394
}

packages/python-sdk/README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ desktop.right_click()
102102
desktop.middle_click()
103103
desktop.scroll(10) # Scroll by the amount. Positive for up, negative for down.
104104
desktop.mouse_move(100, 200) # Move to x, y coordinates
105+
desktop.drag((100, 100), (200, 200)) # Drag using the mouse
105106
```
106107

107108
### Keyboard control
@@ -118,7 +119,7 @@ desktop.write("Fast typing!", chunk_size=50, delay_in_ms=25) # Faster typing
118119
desktop.press("enter")
119120
desktop.press("space")
120121
desktop.press("backspace")
121-
desktop.press(["ctrl", "c"])
122+
desktop.press(["ctrl", "c"]) # Key combination
122123
```
123124

124125
### Screenshot
@@ -156,6 +157,15 @@ out = desktop.commands.run("ls -la /home/user")
156157
print(out)
157158
```
158159

160+
### Wait
161+
162+
```python
163+
from e2b_desktop import Sandbox
164+
desktop = Sandbox()
165+
166+
desktop.wait(1000) # Wait for 1 second
167+
```
168+
159169
## Under the hood
160170

161171
The desktop-like environment is based on Linux and [Xfce](https://www.xfce.org/) at the moment. We chose Xfce because it's a fast and lightweight environment that's also popular and actively supported. However, this Sandbox template is fully customizable and you can create your own desktop environment.

0 commit comments

Comments
 (0)