It is currently Sat Nov 28, 2020 8:56 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Filtering keystrokes
PostPosted: Wed Jun 24, 2020 4:57 pm 
Offline
New User
New User
User avatar

Joined: Thu Jun 18, 2020 3:24 pm
Posts: 7
Location: Monterrey, Mexico
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.

_________________
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


Last edited by cmartinez on Thu Jun 25, 2020 4:29 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Wed Jun 24, 2020 9:16 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8143
Location: Fort Nelson, BC, Canada
Example for Windows, only takes vowels:
Code:
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

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Thu Jun 25, 2020 4:10 am 
Offline
New User
New User
User avatar

Joined: Thu Jun 18, 2020 3:24 pm
Posts: 7
Location: Monterrey, Mexico
netmaestro wrote:
Example for Windows, only takes vowels:
Code:
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


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?

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Thu Jun 25, 2020 5:40 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8143
Location: Fort Nelson, BC, Canada
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.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Thu Jun 25, 2020 5:54 am 
Offline
New User
New User
User avatar

Joined: Thu Jun 18, 2020 3:24 pm
Posts: 7
Location: Monterrey, Mexico
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?

_________________
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Thu Jun 25, 2020 6:09 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8143
Location: Fort Nelson, BC, Canada
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.

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: Filtering keystrokes
PostPosted: Thu Jun 25, 2020 6:13 am 
Offline
New User
New User
User avatar

Joined: Thu Jun 18, 2020 3:24 pm
Posts: 7
Location: Monterrey, Mexico
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... :wink:

_________________
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Seymour Clufley and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye