Skip to content

Commit

Permalink
adds keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
donadev committed Oct 23, 2024
1 parent 32ea343 commit 63472d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ export const getAvailableSimulators = async (platform: Platform) => {
*/
export const isAppInstalled = async (appId: string, platform: Platform) => {
return await cli(commands.isAppInstalled(appId), platform) == "true"
}

/**
* Press a specific key given the keycode
* @param code The code of the key to press
* @param platform The target platform (iOS or Android)
* @returns A promise that resolves with the command output
*/
export const pressKey = async (code: number, platform: Platform) => {
return cli(commands.pressKey(code), platform)
}
8 changes: 7 additions & 1 deletion lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ const commands: {
isAppInstalled: (appId: string): CommandMap => ({
ios: `if idb list-apps | grep -q "${appId}"; then echo true; else echo false; fi`,
android: `if adb shell pm list packages | grep -q "${appId}"; then echo true; else echo false; fi`
})
}),
pressKey: (code: number): CommandMap => {
return {
"ios": `idb ui key ${code}`,
"android": `adb shell input keyevent ${code}`
}
},
};

export default commands;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "udblib",
"version": "0.1.4",
"version": "0.1.5",
"description": "Universal Debug Bridge: Control your iOS Simulators and Android Emulators via cli",
"scripts": {
"build": "tsc",
Expand Down

0 comments on commit 63472d5

Please sign in to comment.