Just starting out? Need help? Post your questions and find answers here.
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Mon Apr 01, 2013 4:05 pm
Hi, please help me...
Keyboard : how to turn ON or OFF the NumLock and CapsLock LED via Purebasic ?
i've found this code and it work but is for Blitzmax
Code: Select all
Extern "Win32"
Function keybd_event (bVk:Int, bScan:Int, dwFlags:Int, dwExtraInfo:Int)
End Extern
Const VK_CAPITAL = $14
Keybd_Event(VK_CAPITAL, 1, KEYEVENTF_EXTENDEDKEY Or 0, 0)
Last edited by
Simo_na on Mon Apr 01, 2013 6:41 pm, edited 1 time in total.
IdeasVacuum
Always Here
Posts: 6426 Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:
Post
by IdeasVacuum » Mon Apr 01, 2013 5:08 pm
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Mon Apr 01, 2013 6:30 pm
thank you !
saw....
a code very long compared to this win32 call ....and this call works fine...
...but one method in purebasic to use the win32 api ?
luis
Addict
Posts: 3895 Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy
Post
by luis » Tue Apr 02, 2013 12:10 am
It's natively supported, just call it: keybd_event_
FYI this API is deprecated, SendInput() (used in the thread linked) is now the recommended way.
"Have you tried turning it off and on again ?"
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Tue Apr 02, 2013 3:19 am
luis wrote: It's natively supported, just call it: keybd_event_
FYI this API is deprecated, SendInput() (used in the thread linked) is now the recommended way.
Thanks , but with this code active
Code: Select all
Procedure record_CallBack(hWnd.i,Msg.i,wParam.i,lParam.i)
If Msg=#MM_WIM_DATA
record_Read (wParam,lParam):record_doFFT (Config\LScope)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
...don't work
i want to send an audio clip @ Bloc Num Led on my keyboard.
IdeasVacuum
Always Here
Posts: 6426 Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:
Post
by IdeasVacuum » Tue Apr 02, 2013 2:21 pm
...don't work
That is really a seperate subject and should really be a seperate post. The code itself, isolated, means very little, so to get help you need to expand your description of what exactly it is that you are trying to do.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Posts: 6426 Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:
Post
by IdeasVacuum » Tue Apr 02, 2013 2:53 pm
...but note, it is better to use the SendInput() method and although it requires more lines of code, it is straightforward stuff.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Tue Apr 02, 2013 3:02 pm
This work !
EDIT
@IdeasVacuum
the code indicated by MachineCode seems work fine in my case.
IdeasVacuum
Always Here
Posts: 6426 Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:
Post
by IdeasVacuum » Tue Apr 02, 2013 6:29 pm
the code indicated by MachineCode seems work fine in my case.
Indeed, but the API function keybd_event is deprecated, which means that at some time in the future, it will not be available for use and therefore it won't work. When that will actually happen, who knows, but if Microsoft have already defined the replacement (which is to use SendInput), then why not use it?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
NabDa
New User
Posts: 3 Joined: Fri Sep 14, 2012 3:58 pm
Location: France
Post
by NabDa » Tue Apr 02, 2013 7:28 pm
Hello !
Maybe these few lines of code may help you:
Code: Select all
;
; SendInput API fonction example
;
Define evnt.INPUT
evnt\type = #INPUT_KEYBOARD
evnt\ki\wVk = #KEYEVENTF_EXTENDEDKEY
evnt\ki\wScan = 0; // hardware scan code for key
evnt\ki\time = 0;
evnt\ki\dwExtraInfo = 0;
; simulate the caps/or num lock key
evnt\type = #INPUT_KEYBOARD;
evnt\ki\wVk = #VK_NUMLOCK; // virtual-key code for the num-lock key (toggle NUMLOCK)
evnt\ki\dwFlags = 0; // 0 for key press
SendInput_(1, @evnt, SizeOf(INPUT));
;simulate key release
evnt\type = #INPUT_KEYBOARD;
evnt\ki\dwFlags = #KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput_(1, @evnt, SizeOf(INPUT));
to toggle CAPSLOCK, just replace:
Code: Select all
evnt\ki\wVk = #VK_NUMLOCK; // virtual-key code for the num lock key (toggle NUMLOCK)
with:
Code: Select all
evnt\ki\wVk = #VK_CAPITAL; // virtual-key code for the caps-lock key (toggle CAPSLOCK)
Voilà !
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Wed Apr 03, 2013 12:13 am
NabDa Cool!
any way to return the state of the #VK's ??
Code: Select all
;
; SendInput API fonction example
;
EnableExplicit
Procedure mykey(vk)
Define evnt.INPUT
evnt\type = #INPUT_KEYBOARD
evnt\ki\wVk = #KEYEVENTF_EXTENDEDKEY
evnt\ki\wScan = 0; // hardware scan code for key
evnt\ki\time = 0;
evnt\ki\dwExtraInfo = 0;
; simulate the caps/or num lock key
evnt\type = #INPUT_KEYBOARD;
If vk=1 : evnt\ki\wVk = #VK_NUMLOCK:EndIf ; // virtual-key code for the num-lock key (toggle NUMLOCK)
If vk=2 : evnt\ki\wVk = #VK_CAPITAL:EndIf ; // virtual-key code for the num-lock key (toggle CAPITAL)
If vk=3 : evnt\ki\wVk = #VK_SCROLL:EndIf ; // virtual-key code for the num-lock key (toggle SCROLL)
evnt\ki\dwFlags = 0; // 0 for key press
SendInput_(1, @evnt, SizeOf(INPUT));
;simulate key release
evnt\type = #INPUT_KEYBOARD;
evnt\ki\dwFlags = #KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput_(1, @evnt, SizeOf(INPUT));
EndProcedure
mykey(1) ; (toggle NUMLOCK)
mykey(2) ; (toggle CAPITAL)
mykey(3) ; (toggle SCROLL)
IdeasVacuum :
Simo_na
Enthusiast
Posts: 177 Joined: Sun Mar 03, 2013 9:01 am
Post
by Simo_na » Wed Apr 03, 2013 3:27 am
Code: Select all
;-------------------------------
; Keyboard Led Handling For Win
;-------------------------------
; v 1.0 - V 1.01
;-------------------------------
EnableExplicit
Global re1,re2,re3 ; read initial state
Global wr1,wr2,wr3 ; read final state
Procedure myinit() ; V1.01 update
re1= GetKeyState_(#VK_NUMLOCK) ;get #VK_NUMLOCK @ start
re2= GetKeyState_(#VK_CAPITAL) ;get #VK_CAPITAL @ start
re3= GetKeyState_(#VK_SCROLL) ;get #VK_CAPITAL @ start
EndProcedure
Procedure mykey(vk)
Define evnt.INPUT
evnt\type = #INPUT_KEYBOARD
evnt\ki\wVk = #KEYEVENTF_EXTENDEDKEY
evnt\ki\wScan = 0; // hardware scan code for key
evnt\ki\time = 0;
evnt\ki\dwExtraInfo = 0;
; simulate the caps/or num lock key
evnt\type = #INPUT_KEYBOARD;
If vk=1 : evnt\ki\wVk = #VK_NUMLOCK:EndIf ; // virtual-key code for the num-lock key (toggle NUMLOCK)
If vk=2 : evnt\ki\wVk = #VK_CAPITAL:EndIf ; // virtual-key code for the num-lock key (toggle CAPITAL)
If vk=3 : evnt\ki\wVk = #VK_SCROLL:EndIf ; // virtual-key code for the num-lock key (toggle SCROLL)
evnt\ki\dwFlags = 0; // 0 for key press
SendInput_(1, @evnt, SizeOf(INPUT));
;simulate key release
evnt\type = #INPUT_KEYBOARD;
evnt\ki\dwFlags = #KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput_(1, @evnt, SizeOf(INPUT));
EndProcedure
Procedure myreset() ; --- this is for only #VK_CAPITAL ---
wr1= GetKeyState_(#VK_NUMLOCK) ; get #VK_NUMLOCK @ end
wr2= GetKeyState_(#VK_CAPITAL) ; get #VK_CAPITAL @ end
wr3= GetKeyState_(#VK_SCROLL) ; get #VK_SCROLL @ end
;---reset #VK_CAPITAL
If re2<>wr2 ; compare re2 and wr2
mykey(2) ; if not equal simulate again...
EndIf
;---
EndProcedure
; --- TEST ---
myinit() ;read the initial state - V1.01 update
mykey(2) ; toggle CAPITAL
Delay (500) ;for verify
myreset() ; reset to initial state.
EDIT
updated to V 1.01
EDIT
From keyboard LED...to external world...