Hello, I'm new to PureBasic, and I'm basically (no pun intended) migrating from VB.NET for the sole reason that I've had it with Microsoft already...
That being said, here's my question.
How does one intercept a keystroke in PureBasic so as to block it or allow it to go through when typing inside an Editor Gadget?
I've tried using the KeyboardPushed instruction along with the necessary InitKeyboard() prior to that, but those instructions seemed aimed at gaming since an OpenScreen() or OpenWindowScreen() command is also required.
I've also tried to capture its event inside a WaitWindowEvent loop, but I have no idea on the details required to make it work.
Thanks in advance to anyone who tries to help me out.
Filtering keystrokes
Filtering keystrokes
Last edited by cmartinez on Thu Jun 25, 2020 4:29 am, edited 1 time in total.
When people are free to pursue goals unfettered by presumed limitations on what they can accomplish, they just may manage some extraordinary feats through the combined application of native talent and hard work. - David Mikkelson
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Filtering keystrokes
Example for Windows, only takes vowels:
Code: Select all
Procedure EditProc(hwnd, msg, wparam, lparam)
oldproc = GetProp_(hwnd, "oldproc")
Select msg
Case #WM_CHAR
If Not FindString("AEIOU", UCase(Chr(wparam)))
ProcedureReturn 0
EndIf
Case #WM_NCDESTROY
RemoveProp_(hwnd, "oldproc")
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure
If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 306, 133)
SetProp_(GadgetID(0), "oldproc", SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @EditProc()))
SetActiveGadget(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
BERESHEIT
Re: Filtering keystrokes
Many thanks for your help ... please keep in mind that I'm a sub-noobie in this language when I ask you this: Where can I find the "RemoveProp_", "SetProp_" and "GetProp_" functions?netmaestro wrote:Example for Windows, only takes vowels:Code: Select all
Procedure EditProc(hwnd, msg, wparam, lparam) oldproc = GetProp_(hwnd, "oldproc") Select msg Case #WM_CHAR If Not FindString("AEIOU", UCase(Chr(wparam))) ProcedureReturn 0 EndIf Case #WM_NCDESTROY RemoveProp_(hwnd, "oldproc") EndSelect ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam) EndProcedure If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) EditorGadget(0, 8, 8, 306, 133) SetProp_(GadgetID(0), "oldproc", SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @EditProc())) SetActiveGadget(0) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf
I've seen many other example codes in this place citing functions ending with a "_" character, and they're nowhere to be found in either the User Manual or the compiler itself.
When people are free to pursue goals unfettered by presumed limitations on what they can accomplish, they just may manage some extraordinary feats through the combined application of native talent and hard work. - David Mikkelson
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Filtering keystrokes
In PureBasic, many commonly-used Windows API functions are already imported to the language for us. They are denoted by an underscore between the function name and the bracket. SetProp_() etc. are API calls. If you ever need an API function that is not already imported (you'll know because the compiler won't recognize it) you can always bring it in yourself from the .lib file (included with PB) using the Import command or from the .dll file using OpenLibrary and prototypes.
BERESHEIT
Re: Filtering keystrokes
Ok, I've just gone through the directories installed along with PureBasic.
One of them's called PureLibraries, so I assume that's what you're referring to. Inside said directory, there's another called Windows\Libraries which is full of *.lib files... I assume said functions can be found in those files.
How do I know which functions are stored in each .lib file, and their specifics? How do I import them into my programs?
Then I also found the SDK directory, with more interesting entries, and yet another one named Catalogs that also drew my attention.
If these questions are too broad, then may I ask if there's an additional manual somewhere that I could look at dealing with this subject?
One of them's called PureLibraries, so I assume that's what you're referring to. Inside said directory, there's another called Windows\Libraries which is full of *.lib files... I assume said functions can be found in those files.
How do I know which functions are stored in each .lib file, and their specifics? How do I import them into my programs?
Then I also found the SDK directory, with more interesting entries, and yet another one named Catalogs that also drew my attention.
If these questions are too broad, then may I ask if there's an additional manual somewhere that I could look at dealing with this subject?
When people are free to pursue goals unfettered by presumed limitations on what they can accomplish, they just may manage some extraordinary feats through the combined application of native talent and hard work. - David Mikkelson
- netmaestro
- PureBasic Bullfrog
- Posts: 8425
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Filtering keystrokes
Google the API you are interested in and read the Microsoft doc on it. It will say at the bottom which .lib file it's contained in as well as which .dll file. Search on the boards here in Tips & Tricks for "Import" and then for "OpenLibrary" and "Prototype". I'm sure many examples will come up and you can see how it's done.
BERESHEIT
Re: Filtering keystrokes
Excellent... thank you so much for your help, and thanks for pointing me in the right direction. I'll do as you say and get back here in case more questions pop up. It's too bad this place doesn't have a "Like" button I could press...
When people are free to pursue goals unfettered by presumed limitations on what they can accomplish, they just may manage some extraordinary feats through the combined application of native talent and hard work. - David Mikkelson