Page 1 of 1
ExamineKeyboard in main loop without Screen
Posted: Sat Oct 07, 2017 9:32 pm
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.
Re: ExamineKeyboard in main loop without Screen
Posted: Mon Oct 09, 2017 5:11 pm
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.
Re: ExamineKeyboard in main loop without Screen
Posted: Mon Oct 09, 2017 9:13 pm
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.
Re: ExamineKeyboard in main loop without Screen
Posted: Mon Oct 09, 2017 9:53 pm
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.