• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how to get control on systems keyboard ?

 
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers,
Is there any way that I can get control on my PC's keyboard. I mean i can control what my keyboard is typing. I can assure that my keyboard cannot type some words, like "what", "why", "who".
If I type "what", there will be a popup saying "you can't type "what" ". I want to block some words . Is it possible ?
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are developing an application right? then why not have this behaviour on your application only instead of acquiring the keyboard, my suggestion would be to have this validation applied to your text fields.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:Is there any way that I can get control on my PC's keyboard. I mean i can control what my keyboard is typing. I can assure that my keyboard cannot type some words, like "what", "why", "who".


It's certainly an interesting idea, and possibly achievable with something like System.setIn(), but probably impractical because there are so many things that a keyboard can supply information for.

For example: if you're executing Scanner.nextInt(), do you really care if someone types in a naughty word? It'll never get into your program because the method will throw an exception long before you ever see it.

However, since you speak of "popups", I assume you're talking about input to a GUI component like a JTextField, in which case I suspect you'll need something like a DocumentFilter.
However, they are not simple; and since I'm no GUI expert, it's probably better that you read the tutorial, or wait for some kind person to suggest an alternative.

However, one place to start is to write a checker method, maybe attached to a 'policeman' class, viz:
HIH

Winston
 
Puspender Tanwar
Ranch Hand
Posts: 658
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anurag Verma wrote:you are developing an application right? then why not have this behaviour on your application only instead of acquiring the keyboard, my suggestion would be to have this validation applied to your text fields.


hello anurag, what if I say that I want to develop an application to block some selected words, i guess almost everywhere and in some selected application if it is possible ...

Thanks winston, Actually for now it doesn't matter whether it should be a popup or something else while someone enters naughty words .
 
author & internet detective
Posts: 41250
849
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To do this in a Java app, the above suggestions work. To do this outside of a specific application, you wouldn't use Java. You could use a "Text Expander" tool (or write your own). That way when the word you want to block, you replace with any empty string.

This open source one should get you started.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:Thanks winston, Actually for now it doesn't matter whether it should be a popup or something else while someone enters naughty words .


You're most welcome.

Actually, I suspect it does matter, because "pop-ups" are really only applicable to a GUI environment. Furthermore, it's the "almost" in "almost everywhere" that's going to cause you headaches.

For a truly generic solution, you're going to need something that deals with both the input (ie, when to check for naughty words) and output (how do you tell your "user" - if there is one - that they committed a sin).

I'm not familiar with Jeanne's suggestion, so it's possible it may do what you want; but my suggestion would be to deal with the first part of the problem - identifying bad words (or sequences) in a string - and then (once you know it's working) decide how you want to plug it in to a more general framework.

HIH

Winston
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Puspender Tanwar wrote:If I type "what", there will be a popup saying "you can't type "what" ". I want to block some words . Is it possible ?



As a user, I would be very irritated if I was prompted while typing. Imagine if your tool does not like "what", but I am typing "whatever". An alternative approach is that allow the user to type whatever he wants but dont allow to save your form until everything is valid. Here too, some well made guis simply highlight the field with some color and an error message when it loses focus to tell the user what he typed is invalid.

Its non intrusive approach. No one likes popups.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like Salvin's approach. (Have a cow Salvin! Moo!)

At work, we use custom chat clients, which enable us to communicated within the office as well as with clients. This chat client has such a kind of filter (amongst others)
You can type what you want (no popups) but if the text contains any banned words, the Send button is disabled, the word(s) highlighted and you get a warning text telling you about it. Much better usability than popups.

PS. Java has a built in highlighter too!
https://docs.oracle.com/javase/7/docs/api/javax/swing/text/Highlighter.html
 
You had your fun. Now it's time to go to jail. Thanks for your help tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic