Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Sending keys to a game function not working

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
inval1d
How do I cheat?
Reputation: 0

Joined: 10 May 2015
Posts: 5

PostPosted: Wed Jul 22, 2015 6:46 pm    Post subject: Sending keys to a game function not working Reply with quote

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
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Jul 22, 2015 6:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
inval1d
How do I cheat?
Reputation: 0

Joined: 10 May 2015
Posts: 5

PostPosted: Wed Jul 22, 2015 7:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Jul 23, 2015 10:11 am    Post subject: Reply with quote

http://www.kbdedit.com/manual/low_level_vk_list.html
Enter has a value of 13
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites