keyboard stroke, which solution to use ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

keyboard stroke, which solution to use ?

Post by Fig »

I created a chat in a WindowedScreen. (I didn't use Pb's Gui and made my own)
I was wondering if someone has a good snipped to capture keyboard, including repetition, Delete, multiple keypressed, Shift etc...
This is a snipped of the code i use. As you can see it's not very smooth for typing. (test shifted symbol for exemple and repetitions...)

Code: Select all

Xres=1024:yRes=600
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0:MessageRequester("Error", "Can't open the sprite system", 0):End:EndIf
If OpenWindow(0, 0, 0,Xres, Yres, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, xres, yres, 0, 0, 0)=0:MessageRequester("Error", "Can't open windowed screen!", 0):EndIf    

Repeat
   FlipBuffers()
   ClearScreen(#Black)
   Repeat:Event = WindowEvent():Until Event = 0   
   ExamineKeyboard()

   If KeyboardReleased(#PB_Key_Back)
      text$ = Left(text$, Len(text$)-1)
   ElseIf KeyboardPushed(#PB_Key_PadEnter)
      text$+Chr(13)
   Else  
      resultat$=KeyboardInkey()
      If FindString("1234567890 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzéêïèçàù.,!?;:§%*µ+$£^¨=)°@_`|-(\{#~&²<>"+Chr(13), resultat$)
         text$ + resultat$
      EndIf
   EndIf
   
   StartDrawing(ScreenOutput())
   DrawText(0,0,"Type your text...   [Escape] To quit")
   DrawText(0,40,text$)
   StopDrawing()
Until KeyboardPushed(#PB_Key_Escape)
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: keyboard stroke, which solution to use ?

Post by Fig »

Just hit the french Azerty 'M' ',?' keyboard bug... http://www.purebasic.fr/english/viewtop ... =4&t=45836
Last edited by Fig on Sun Aug 20, 2017 6:42 pm, edited 5 times in total.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: keyboard stroke, which solution to use ?

Post by falsam »

Fig wrote:Just hit the french 'M' keyboard bug...
KeyboardMode(#PB_Keyboard_International) :wink:

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: keyboard stroke, which solution to use ?

Post by Fig »

Follow the link... "M" return 2 values 50 and 32 and "," (the key at right to "n") return no value. (so of course your code works...)
Bugged since 2011... \o/

You can launch my code also and hit the "m" you'll see ",m"
Last edited by Fig on Sat Aug 19, 2017 7:43 pm, edited 2 times in total.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: keyboard stroke, which solution to use ?

Post by falsam »

Oops Sorry !! I forgot to run the test with KeyboardPushed() :oops:

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: keyboard stroke, which solution to use ?

Post by Fig »

M key has 2 codes M code and ,? code
,? key has 0 code.

,? and M have been mapped on the same key. (,? is the M key on Qwerty keyboard, at right hand to the N)
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply