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 


Mapping vKey(s) using lua CE

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Jan 26, 2017 8:09 pm    Post subject: Mapping vKey(s) using lua CE This post has 1 review(s) Reply with quote

hi there,

Code:
function onKeyPress(sender, key)

 key_enter = UDF1.CEEdit1.Text

   if key_enter == "" then
    UDF1.CELabel2.Caption = "Waiting"
    nr = ""
    else
    key = string.format("VK_"..tostring(key_enter))
    print(key)                          --- see what key string contains
    nr=string.byte(key_enter)   --- get key code as a byte
   end

 UDF1.CELabel2.Caption = string.format("Button pressed = "..key_enter.." ("..nr..")")
-- return key
end

UDF1.show()
UDF1.CEEdit1.onClick = onKeyPress  --- actually want make this as onChange instead onClick


Problem :
1. nr=string.byte(key_enter) --> always return the first character from string input
2. If trying input special key mapping e.q "VK_CONTROL, VK_LBUTTON", etc"... will point as no.1
3. Is any other way to substitute "string.byte" to get VK code output as string ?
4. If not (no.3) it's look like need put all VK code as a table and then look up from there to matching user input.

or something like this written on AutoIt :

Code:
Local $k = _VkKeyScan('A')
ConsoleWrite(StringFormat('A   VkCode:%s   HexCode:%s\n',$k,Hex($k,2)))

Func _VkKeyScan($s_Char)
Local $a_Ret = DllCall("user32.dll", "short", "VkKeyScan", "ushort", AscW($s_Char))
If @error Then Return SetError(@error, @extended, -1)
Return BitAND($a_Ret[0], 0xFF) ;Low Byte
EndFunc   ;==>_VkKeyScan


Thanks
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 Jan 26, 2017 9:51 pm    Post subject: Reply with quote

Code:
virtual_keys = {}
for i, v in pairs(_G) do
  if type(i) == "string" then
    if i:sub(1, 3) == "VK_" then
      virtual_keys[v] = i
    end
  end
end

function CEEdit1KeyDown(sender, key)
  print(virtual_keys[key])
  return key
end
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Jan 26, 2017 11:25 pm    Post subject: Reply with quote

Thanks Zanzer sir,

With your script, will give result :

VK_5 if numpad 5 button pressed on keyboard,
VK_CAPITAL if CAPSLOCK button pressed on keyboard, etc

But, what I am trying to do is :
if numpad 5 pressed, a label will give information "Button VK_5 pressed = 5 (Code : 53), which 53 is vKey code number for numpad 5.

Next, the problem is if I pressed C, it will give result vKey code = 67.
(input C via textbox and click to get vKey code, give result 67)
but now, how to input "CANCEL" via textbox, because it will return 67 too, because function string.byte(char) only read the first character from textbox.

in short, if user input "CANCEL" in textbox, then a label will show the correct vKey code (as picture attach).

Thanks

EDIT : Done..

Code:
UDF1.show()
UDF1.CELabel3.Visible = false
UDF1.CELabel4.Visible = false
UDF1.CELabel5.Visible = false

virtual_keys = {}
for i, v in pairs(_G) do
  if type(i) == "string" then
    if i:sub(1, 3) == "VK_" then
     virtual_keys[v] = i
     key1 = virtual_keys[v]

   end
  end
end

function CEEdit1KeyDown(sender, key)
--  print(virtual_keys[key])
  a = virtual_keys[key]
  sh = tostring(a)
  font = getProperty(UDF1.CELabel3, "Font")
  setProperty(font , "Style", "[fsBold]")
  setProperty(font , "Height", "26")
  setProperty(font , "Color", 25866625)
  UDF1.CELabel2.Caption = "Last pressed button : "
  UDF1.CELabel3.Visible = true
  UDF1.CELabel4.Visible = true
  UDF1.CELabel5.Visible = true
  UDF1.CELabel3.Caption = sh
--  print(key)
  font = getProperty(UDF1.CELabel5, "Font")
  setProperty(font , "Style", "[fsBold]")
  setProperty(font , "Height", "26")
  setProperty(font , "Color", 25866625)
  UDF1.CELabel5.Caption = tostring(key)
  return key
end

function CEButton1Click(sender)
 UDF1.CELabel3.Visible = false
 UDF1.CELabel4.Visible = false
 UDF1.CELabel5.Visible = false
 UDF1.CELabel2.Caption = "Waiting.."
 UDF1.CEEdit1.Text = ""
end

function openVTKeyboard(sender)
 if sender.Checked then
 shellExecute'osk.exe'
 openProcess'osk.exe'
 else
 autoAssemble[[alloc(n,64)
 createthread(n)
 n:
 push 0
 call exitProcess
 ret]]
 end
end

function close()
 closeCE()
 return caFree
end

UDF1.show()
UDF1.CECheckbox1.onChange = openVTKeyboard
form_onClose(UDF1, close)


Maybe someone able to providing the script with adding function to set and change for hotkey.



Capture.JPG
 Description:
 Filesize:  22.9 KB
 Viewed:  10706 Time(s)

Capture.JPG



CRDR - Keyboard Key Mapper Ver.1.0.CT
 Description:

Download
 Filename:  CRDR - Keyboard Key Mapper Ver.1.0.CT
 Filesize:  41.68 KB
 Downloaded:  974 Time(s)

Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Jan 27, 2017 7:48 pm    Post subject: Reply with quote

You trying to do this?
http://forum.cheatengine.org/viewtopic.php?p=5710667

These also exist:
Code:
print(shortCutToText(16449))
print(textToShortCut("Shift+A"))
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Fri Jan 27, 2017 8:20 pm    Post subject: Reply with quote

Zanzer sir,

http://forum.cheatengine.org/viewtopic.php?p=5710667

I have read and tried this CE plugin, created by mgr.

What I want to do with my script is, to get know what is vKeys value codes for some keyboard / mouse buttons (if not all), so I don't need to browsing it or open reference files about it, if needed sometimes. More like giving info about buttons.

Btw,

Code:
print(shortCutToText(16449))    ----> Result : Ctrl + A
print(textToShortCut("Shift+A"))  -----> Result : 8257


These is keystrokes shortcut for Free Pascal / Lazarus IDE.

Thank you and regards
Back to top
View user's profile Send private message
scarface010305
Newbie cheater
Reputation: 0

Joined: 15 Jun 2017
Posts: 22

PostPosted: Sat Jun 17, 2017 4:08 am    Post subject: Reply with quote

Well done !

I want to ask, if its possible to create a Hotkey with this script.

I tried this:

Code:
hotkey1 = createHotkey(myfunction1, sh)


But it wont work for me.
Only if i write the VK.. Code in the Script it works.

Any idea ?
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