Skip to content

Commit 5c4f895

Browse files
authored
docs: update code example
1 parent dc54975 commit 5c4f895

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ its wallpaper
2121
usb = luausb.create({ id = 0, type = "keyboard" })
2222
kb = usb.dev[1]
2323

24-
local file = "https://i.redd.it/ur1mqcbpxou51.png"
24+
local file = prompt("Wallpaper to download?", "https://i.imgur.com/46wWHZ3.png")
2525

2626
while true do
27-
-- wait for the phone to be plugged into a computer
28-
while not kb.test() do usb.delay(1000) end
29-
30-
usb.delay(1000)
27+
print("idle")
3128

32-
kb.press_keys(kb.LSUPER, kb.R) -- open the Windows run dialog
33-
usb.delay(2000) -- wait 2 seconds
34-
kb.send_string("powershell\n") -- pop open a powershell window
35-
usb.delay(2000)
36-
37-
-- enter a script that changes your wallpaper
38-
kb.send_string("[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ..
29+
-- wait for the phone to be plugged into a computer
30+
while usb.state() == "not attached" do
31+
wait(1000)
32+
end
33+
34+
print("running")
35+
wait(1000)
36+
37+
kb.chord(MOD_LSUPER, KEY_R) -- open Windows run dialog
38+
wait(2000) -- wait for it to open
39+
kb.string("powershell\n") -- open powershell
40+
wait(2000)
41+
-- execute a script that downloads and changes the wallpaper
42+
kb.string("[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;" ..
3943
"(new-object System.Net.WebClient).DownloadFile('" .. file .. "',\"$Env:Temp\\b.jpg\");\n" ..
4044
"Add-Type @\"\n" ..
4145
"using System;using System.Runtime.InteropServices;using Microsoft.Win32;namespa" ..
@@ -48,8 +52,11 @@ while true do
4852
"[W.S]::SW(\"$Env:Temp\\b.jpg\")\n" ..
4953
"exit\n")
5054

51-
-- wait for the phone to be unplugged
52-
while kb.test() do usb.delay(1000) end
55+
print("done")
56+
-- wait until the phone is unplugged
57+
while usb.state() == "configured" do
58+
wait(1000)
59+
end
5360
end
5461
```
5562

0 commit comments

Comments
 (0)