Performs a right-click at the specified coordinates on the screen. The right-click action simulates pressing and releasing the right mouse button, which typically opens context menus in applications.
The request body is a JSON object with the following properties:
{
"x": number, // X coordinate on the screen
"y": number // Y coordinate on the screen
}
| Parameter | Type | Required | Description |
|---|---|---|---|
| x | number | Yes | The X-coordinate (horizontal position) for the right-click action. The X-coordinate is measured in pixels from the left edge of the screen. |
| y | number | Yes | The Y-coordinate (vertical position) for the right-click action. The Y-coordinate is measured in pixels from the top edge of the screen. |
{
"x": 500,
"y": 300
}
The response is a JSON object containing the result of the operation:
{
"Success": boolean, // Whether the operation was successful
"Message": "string", // Result message or error description
"Timestamp": "string" // ISO timestamp of the operation
}
| Field | Type | Description |
|---|---|---|
| Success | boolean | Indicates whether the right-click operation was successful. Returns true if the operation completed successfully, false otherwise. |
| Message | string | Additional information about the operation. If the operation failed, this will contain an error message. This field might be empty if the operation was successful. |
| Timestamp | string | The date and time when the right-click operation was executed (ISO format). |
{
"Success": true,
"Message": "Right-click action performed successfully",
"Timestamp": "2023-06-15T10:30:45.123Z"
}
import requests
import json
def mouse_right_click(x, y, api_key):
"""
Performs a right-click at the specified coordinates.
Args:
x (int): The X-coordinate (horizontal position).
y (int): The Y-coordinate (vertical position).
api_key (str): The API key for authentication.
Returns:
dict: The response from the server.
"""
url = "http://localhost:5000/tools-api/mouse/rightclick"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"x": x,
"y": y
}
response = requests.post(url, headers=headers, json=payload)
if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code}")
print(response.text)
return None
# Example usage
if __name__ == "__main__":
api_key = "your_api_key"
# Right-click at coordinates (500, 300)
result = mouse_right_click(500, 300, api_key)
if result and result["success"]:
print("Right-click successful!")
print(f"Timestamp: {result['timestamp']}")
else:
print("Right-click failed.")
interface MouseRightClickRequest {
x: number;
y: number;
}
interface ActionResponse {
success: boolean;
message?: string;
timestamp: string;
}
/**
* Performs a right-click at the specified coordinates.
*
* @param x - The X-coordinate (horizontal position).
* @param y - The Y-coordinate (vertical position).
* @param apiKey - The API key for authentication.
* @returns A promise that resolves to the action response.
*/
async function mouseRightClick(
x: number,
y: number,
apiKey: string
): Promise {
const url = 'http://localhost:5000/tools-api/mouse/rightclick';
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
};
const payload: MouseRightClickRequest = {
x,
y
};
try {
const response = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return await response.json() as ActionResponse;
} catch (error) {
console.error('Error performing right-click:', error);
throw error;
}
}
// Example usage
async function example() {
const apiKey = 'your_api_key';
try {
// Right-click at coordinates (500, 300)
const result = await mouseRightClick(500, 300, apiKey);
if (result.success) {
console.log('Right-click successful!');
console.log(`Timestamp: ${result.timestamp}`);
} else {
console.log('Right-click failed:', result.message);
}
} catch (error) {
console.error('An error occurred:', error);
}
}
example();
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace SmoothOperatorClient
{
public class ToolsServerClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
public ToolsServerClient(string apiKey)
{
_httpClient = new HttpClient();
_httpClient.BaseAddress = new Uri("http://localhost:5000/");
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
_apiKey = apiKey;
}
///
/// Performs a right-click at the specified coordinates.
///
/// The X-coordinate (horizontal position).
/// The Y-coordinate (vertical position).
/// A task representing the asynchronous operation with the action response.
public async Task MouseRightClickAsync(int x, int y)
{
var request = new MouseActionRequest
{
X = x,
Y = y
};
var json = JsonSerializer.Serialize(request, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("tools-api/mouse/rightclick", content);
response.EnsureSuccessStatusCode();
var responseContent = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize(responseContent, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
});
}
}
public class MouseActionRequest
{
public int X { get; set; }
public int Y { get; set; }
}
public class ActionResponse
{
public bool Success { get; set; }
public string Message { get; set; }
public DateTime Timestamp { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var apiKey = "your_api_key";
var client = new ToolsServerClient(apiKey);
try
{
// Right-click at coordinates (500, 300)
var result = await client.MouseRightClickAsync(500, 300);
if (result.Success)
{
Console.WriteLine("Right-click successful!");
Console.WriteLine($"Timestamp: {result.Timestamp}");
}
else
{
Console.WriteLine($"Right-click failed: {result.Message}");
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
}