ExamineKeyboard in main loop without Screen

Just starting out? Need help? Post your questions and find answers here.
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

ExamineKeyboard in main loop without Screen

Post by mdp »

How can one use ExamineKeyboard() (the Keyboard library) without a Screen?
In the examples I can only see these commands used within a BindEvent(#PB_Event_RenderFrame, @callback())

I just started coding in SB this evening; the first think I need is a Console library, and I wanted to implement it in a Window, in TextGadgets.
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Re: ExamineKeyboard in main loop without Screen

Post by mdp »

One half solution would be to
!document.addEventListener('keydown', function(event) { f_processeventkeycode(event.keyCode); });
but keycodes are too low level - they get 'a', but not 'A' nor 'â'. Which is probably the same that the Keyboard library gets. I suppose for my purpose I want something different.
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: ExamineKeyboard in main loop without Screen

Post by falsam »

Code: Select all

Procedure InitKey(callback)
 ! document.addEventListener('keypress', (event) => {
 ! const keyName = event.key;

 ! v_callback(keyName);
 ! })  
EndProcedure

;// Zone test
Procedure Dummy(Key.s)
  Debug Key
EndProcedure

OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Background)
InitKey(@Dummy())
This code does not detect Alt, Ctrl, F1->F12, Escape keys.

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
mdp
Posts: 31
Joined: Fri Oct 06, 2017 10:37 am

Re: ExamineKeyboard in main loop without Screen

Post by mdp »

falsam wrote:This code does not detect Alt, Ctrl, F1->F12, Escape keys.
Right, special combinations like for example [AltGr]+[Shift]+[^], [e] → 'ê' do not work.
So, I am resorting (for the specific purpose I had) to a TextGadget for the output + a StringGadget for the input, adding a
!spider_GadgetID(v_inputstringgadget).div.addEventListener('keydown', function(event) { f_inputgadgetkeydown(event.keyCode); });
to detect the [ENTER] key and trigger the "after string completed" process.
Post Reply