View previous topic :: View next topic |
Author |
Message |
inval1d How do I cheat? Reputation: 0
Joined: 10 May 2015 Posts: 5
|
Posted: Wed Jul 22, 2015 6:46 pm Post subject: Sending keys to a game function not working |
|
|
Hello, I have the following LUA script that I wrote:
Code: | function sleep(s)
local ntime = os.time() + s
repeat until os.time() > ntime
end
function sendKey(key)
if string.len(key) == 1 then
keyDown(string.byte(key,1))
else
for i=1,string.len(key) do
keyDown(string.byte(key:sub(i,i),1))
sleep(1)
end
end
end |
If I execute that, and then execute
Code: |
sleep(5)
--now I tab into the game
sendKey("lol")
|
it doesn't work. It just seems to type a "/" what is wrong with my code? Thanks![/code]
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Jul 22, 2015 6:55 pm Post subject: |
|
|
Make the string uppercase.
And don't forget the keyUp()
Code: | function sendKeys(keys)
keys = keys:upper()
for i=1,keys:len() do
local key = keys:byte(i)
keyDown(key)
sleep(100)
keyUp(key)
end
end
sendKeys("abc123") |
Last edited by Zanzer on Wed Jul 22, 2015 7:03 pm; edited 2 times in total |
|
Back to top |
|
|
inval1d How do I cheat? Reputation: 0
Joined: 10 May 2015 Posts: 5
|
Posted: Wed Jul 22, 2015 7:00 pm Post subject: |
|
|
Thanks, it worked! This is what I ended up doing:
Code: | function sendKey(key)
if string.len(key) == 1 then
keyDown(string.byte(key:upper(),1))
else
for i=1,string.len(key) do
keyDown(string.byte(key:upper():sub(i,i),1))
sleep(100)
end
end
end | [/code]
In addition, how would I send keys like "enter" and things of that nature?
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
|
Back to top |
|
|
|