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 


Synchronize Keypress

 
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: 1668

PostPosted: Wed May 27, 2020 8:03 pm    Post subject: Synchronize Keypress Reply with quote

This is a sample of my project for a kindergarten that learns the basic musical note's purpose.
I am using an old 'Jurassic era' function from kernel32, it's a 'beep' function and uses it for a simple sound pad.

Sample code:

Code:
if frm then frm.destroy() end

frm = createForm()
frm.setSize(300,150)
frm.Position = 'poScreenCenter'

local cl = 15
local i
for i=1,8 do
 local keyname= 'panel0'..i
 local keyPanel=createPanel(frm)
  _G[keyname]=keyPanel
  keyPanel.Left = cl
  keyPanel.Top = 10
  keyPanel.Width = 30
  keyPanel.Height = 120
  keyPanel.Color = 0xffffff
  cl = cl+35
end

function sBeep(freq, dur)
 return executeCodeLocalEx('kernel32.Beep', freq, dur)
end

duration = 100

function keypressDown(sender, Key)
 frm.setFocus()
 if (Key == VK_Z) then
    panel01.Color = 52582
    sBeep(261, duration)
 elseif (Key == VK_X) then
    panel02.Color = 52582
    sBeep(293, duration)
 elseif (Key == VK_C) then
    panel03.Color = 52582
    sBeep(329, duration)
 elseif (Key == VK_V) then
    panel04.Color = 52582
    sBeep(349, duration)
 elseif (Key == VK_B) then
    panel05.Color = 52582
    sBeep(391, duration)
 elseif (Key == VK_N) then
    sBeep(440, duration)
    panel06.Color = 52582
 elseif (Key == VK_M) then
    sBeep(493, duration)
    panel07.Color = 52582
 elseif (Key == VK_A) then
    sBeep(523, duration)
    panel08.Color = 52852
 end
end
frm.OnKeyDown = keypressDown

function keypressUp(sender, Key)
 frm.setFocus()
 if (Key == VK_Z) then
    panel01.Color = 0xffffff
 elseif (Key == VK_X) then
    panel02.Color = 0xffffff
 elseif (Key == VK_C) then
    panel03.Color = 0xffffff
 elseif (Key == VK_V) then
    panel04.Color = 0xffffff
 elseif (Key == VK_B) then
    panel05.Color = 0xffffff
 elseif (Key == VK_N) then
    panel06.Color = 0xffffff
 elseif (Key == VK_M) then
    panel07.Color = 0xffffff
 elseif (Key == VK_A) then
    panel08.Color = 0xffffff
 end
end
frm.OnKeyUp = keypressUp

frm.Show()


Problem:
If the 'duration' higher than 100 (say 200), the pads color change when key pressed (down/up) has delayed as per milliseconds. Mean not Synchronize between output sounds, key down/key up and the panel color change.

Any solutions to fix it?. Use timer?.
Honestly, I avoid using timers because using timers not with the right precision will cause memory leaks.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1532

PostPosted: Thu May 28, 2020 4:25 am    Post subject: Reply with quote

Man, you should probably change the "beep" sound.
I think "beep" is not suitable for getting the right sound.
Otherwise, very fine calculations need to be made.
This may require a music teacher. Smile
The number values you use in the chart below are available.
And I still think the "beep" sound is not suitable for toning.

EDIT ;
Code:

duration = 600
local clrTimer=createTimer() clrTimer.Interval=duration-100 clrTimer.Enabled=false

function Z() panel01.Color = 0x00ff00 sBeep(261, duration) clrTimer.Enabled=true end
function X() panel02.Color = 0x00ff00 sBeep(393, duration) clrTimer.Enabled=true end
function C() panel03.Color = 0x00ff00 sBeep(429, duration) clrTimer.Enabled=true end
function V() panel04.Color = 0x00ff00 sBeep(549, duration) clrTimer.Enabled=true end
function B() panel05.Color = 0x00ff00 sBeep(691, duration) clrTimer.Enabled=true end
function N() panel06.Color = 0x00ff00 sBeep(740, duration) clrTimer.Enabled=true end
function M() panel07.Color = 0x00ff00 sBeep(893, duration) clrTimer.Enabled=true end
function A() panel08.Color = 0x00ff00 sBeep(923, duration) clrTimer.Enabled=true end

htk1=createHotkey(Z, VK_Z) htk2=createHotkey(X, VK_X) htk3=createHotkey(C, VK_C)
htk4=createHotkey(V, VK_V) htk5=createHotkey(B, VK_B) htk6=createHotkey(N, VK_N)
htk7=createHotkey(M, VK_M) htk8=createHotkey(A, VK_A)

function keypressUp(sender, Key)
 frm.setFocus()
panel01.Color=0xffffff panel02.Color=0xffffff panel03.Color=0xffffff
panel04.Color=0xffffff panel05.Color=0xffffff panel06.Color=0xffffff
panel07.Color=0xffffff panel08.Color=0xffffff
 end

clrTimer.OnTimer=function() keypressUp() clrTimer.Enabled=false end



notesinvert.gif
 Description:
 Filesize:  10.85 KB
 Viewed:  1923 Time(s)

notesinvert.gif



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu May 28, 2020 12:21 pm    Post subject: Reply with quote

Quote:
Aylin: Man, you should probably change the "beep" sound.


Don't worry about the beep sound. I can change the beep sound to whatever sound wanted, for example, turn to real piano sound, stell drum bass sound, animal sound, etc. That is not a real important point.

For now, my goal is finding and providing the OOP logical programming for the events handler, such as clicking, key pressing, auto-playing, etc.

However, thank you for the sample script.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1532

PostPosted: Thu May 28, 2020 12:31 pm    Post subject: Reply with quote

I didn't think it could change with other sounds.
But the "beep" sound can play music in its current form.
It just doesn't sound like it sounds.
You are on good work again, congratulations.

Here is my new project; 61 notes and full Piano.



Piano2.PNG
 Description:
 Filesize:  50.73 KB
 Viewed:  1902 Time(s)

Piano2.PNG



_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu May 28, 2020 1:12 pm    Post subject: Reply with quote

Aylin wrote:
I didn't think it could change with other sounds.
But the "beep" sound can play music in its current form.
It just doesn't sound like it sounds.
You are on good work again, congratulations.

Here is my new project; 61 notes and full Piano.


Here, example with real piano sound:

Code:
if frm then frm.destroy() end

frm = createForm()
frm.setSize(300,200)
frm.Position = 'poScreenCenter'

local cl = 15
local i
for i=1,8 do
 local keyname= 'panel0'..i
 local keyPanel=createPanel(frm)
  _G[keyname]=keyPanel
  keyPanel.Left = cl
  keyPanel.Top = 10
  keyPanel.Width = 30
  keyPanel.Height = 120
  keyPanel.Color = 0xffffff
  cl = cl+35
end

demobtn = createButton(frm)
demobtn.setSize(100,30)
demobtn.setPosition(100,150)
demobtn.Caption = 'Demo'

function sBeep(freq, dur)
 return executeCodeLocalEx('kernel32.Beep', freq, dur)
end

duration = 100

function keypressDown(sender, Key)
 frm.setFocus()
 if (Key == VK_Z) then
    panel01.Color = 52582
    playSound(findTableFile('C.wav'))
    --sBeep(261, duration)
 elseif (Key == VK_X) then
    panel02.Color = 52582
    playSound(findTableFile('D.wav'))
    --sBeep(293, duration)
 elseif (Key == VK_C) then
    panel03.Color = 52582
    playSound(findTableFile('E.wav'))
    --sBeep(329, duration)
 elseif (Key == VK_V) then
    panel04.Color = 52582
    playSound(findTableFile('F.wav'))
    --sBeep(349, duration)
 elseif (Key == VK_B) then
    panel05.Color = 52582
    playSound(findTableFile('G.wav'))
    --sBeep(391, duration)
 elseif (Key == VK_N) then
    playSound(findTableFile('A.wav'))
    panel06.Color = 52582
    --sBeep(440, duration)
 elseif (Key == VK_M) then
    playSound(findTableFile('B.wav'))
    panel07.Color = 52582
    --sBeep(493, duration)
 elseif (Key == VK_A) then
    playSound(findTableFile('C1.wav'))
    panel08.Color = 52852
    --sBeep(523, duration)
 end
end
frm.OnKeyDown = keypressDown

function keypressUp(sender, Key)
 frm.setFocus()
 if (Key == VK_Z) then
    sleep(100)
    panel01.Color = 0xffffff
 elseif (Key == VK_X) then
     sleep(100)
    panel02.Color = 0xffffff
 elseif (Key == VK_C) then
     sleep(100)
    panel03.Color = 0xffffff
 elseif (Key == VK_V) then
     sleep(100)
    panel04.Color = 0xffffff
 elseif (Key == VK_B) then
     sleep(100)
    panel05.Color = 0xffffff
 elseif (Key == VK_N) then
     sleep(100)
    panel06.Color = 0xffffff
 elseif (Key == VK_M) then
     sleep(100)
    panel07.Color = 0xffffff
 elseif (Key == VK_A) then
     sleep(100)
    panel08.Color = 0xffffff
 end
end
frm.OnKeyUp = keypressUp

frm.Show()


And the picture attached is my old project using Python programming.
I just take funs by trying to ported the project to Lua.



Capture.JPG
 Description:
VCL Midi Keyboard
 Filesize:  70.37 KB
 Viewed:  1897 Time(s)

Capture.JPG



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1532

PostPosted: Thu May 28, 2020 5:53 pm    Post subject: Reply with quote

You will probably do the best. I believe this.

Here is a work in progress.
Play all notes with a single code.


Link




Code:
Piyano.CEPanel1.Caption=" ♬ ♪ ♭ ♫ ♪  ©  Aylin  Full  Piano  v2.00  ♬ ♪ ♭ ♫ ♪ "
function play1(song1, opt1)
 if not initializeMP3Player() then return end
 local fileName
 fileName = song1
 MP3PlayerSendCommand("close "..opt1, 0, 0, 0)
 MP3PlayerSendCommand("open "..fileName.." type mpegvideo alias "..opt1, 0, 0, 0)
 MP3PlayerSendCommand("play "..opt1, 0, 0, 0)

end

function N1() play1(pth.."a49.mp3", "notes1") end

-- ...

function N61() play1(pth.."b66.mp3", "notes61") end

--and  mouse ..

function VocalPan(item)
--item.caption=cap1 item.OptimalFill=true item.Tag=60 item.WordWrap=true
local clr=0xffffff local clr1=0xdfdfdf

item.OnMouseMove=function() item.color=clr1 end
item.OnMouseLeave=function() item.color=clr end
end

VocalPan(Piyano.a49) VocalPan(Piyano.a50) VocalPan(Piyano.a51) VocalPan(Piyano.a52)

Piyano.a49.OnClick=N1 Piyano.a50.OnClick=N2 --... etc. ...

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu May 28, 2020 8:31 pm    Post subject: Reply with quote

@Aylin. Good work and inspiring. Congratulations.
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
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