Solved

Locking Windows 95/98

Posted on 1999-01-21
24
186 Views
Last Modified: 2010-04-02
I need to lock Windows' special keys (such as CTRL-ALT-DELETE, ALT-TAB, etc.) in my application. Any ideas how ?

Sample code would be cool.

(The Windows-Key should also be deactivated.)
0
Comment
Question by:sbartok
  • 9
  • 7
  • 4
  • +1
24 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The only way I've seen is to write a special keyboard driver.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
The only way to do this is using a system-wide message hook (see 'SetWindowsHookEx()' and 'WH_GETMESSAGE', the hook has to reside in a DLL), e.g.:

LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;
    MSG     msg;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   /* ... check whether it's a key message */
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_KEYFIRST,
                            WM_KEYLAST,
                            PM_NOREMOVE
                        )
        )
        {
/* this one is for us, so check key state */
if ( 0x80000000 & GetKeyState(VK_LMENU)
     && 0x80000000 & GetKeyState(VK_CONTROL)
            )
            {
            
            /* appropriate action, e.g. suppress msg by removing it /*
            PeekMessage (   &msg,
                            pmsg->hwnd,
                            WM_MOUSEFIRST,
                            WM_MOUSELAST,
                            PM_REMOVE
                        );
           }
        }

 
}


0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Ooops, tach' auch Sacha! Und Danke für den Weihnachtsgruß ;-)

Jürgen <s>
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
A system hook supposidly (I never tried, but I've seen it mentioned more than once) doesn't catch these.  
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
nietod - it's not intended to catch the combination, but they can be suppressed if one key is blocked (i.e. the message never reaches explorer.exe) - this doesn't work on NT, of course...
0
 
LVL 1

Author Comment

by:sbartok
Comment Utility
Hmm,
hi jks, ich glaub ich steh auf der leitung, weihnachtsgruss.
wie is deine e@Mail ?
und nun zum problem (in englisch fuer alle)
ok, i didn't work with dll's before. can you tell
me "easy" :-) steps how to create one ?
if yes, write it as an answer and get 150 points.
(fuer die dll hab ich die punkte um 50 erhoeht.
0
 
LVL 1

Author Comment

by:sbartok
Comment Utility
jetzda, juergen, hi !
hab schnell ins adressbuch geschaut und klingeling hats gemacht.
sorry :-)
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
>> but they can be suppressed if one key is blocked
I see.  makes sense.  Have you actually made it work?

0
 
LVL 1

Author Comment

by:sbartok
Comment Utility
nope, not yet, read my comment :
>> ok, i didn't work with dll's before. can you tell
me "easy" :-) steps how to create one ? <<

still waiting for jkr, seems to be logged off the net.
(in germany it's 10:51pm)
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Sacha - of course i could tell you in easy steps how to create it, but IMHO the above code says all. Alternatively, i could send you a sample project, as posting the whole code would be a little bit too much. (About the example: The executable is available at our website, see download->xclip.zip. The source will follow tomorrow, actually i'm already @home. No need to post your email, though ;-)

nietod - as you might know, i mostly (solely ;-) use NT (on which the logon sequence definitely can't be blocked). But the task it should perform isn't new (see http://www.experts-exchange.com/topics/bin/Q.10087391, PAQ, 10pts) - this was about the same problem, and the above code made it...
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Still here, but not for very much longer (ich muss noch kochen, Hunger tut weh ;-)
0
 
LVL 10

Accepted Solution

by:
viktornet earned 150 total points
Comment Utility
Try this one....

int Dummy;

SystemParametersInfo (97, 1, &Dummy, 0); //Disable those keys....

SystemParametersInfo (97, 0, &Dummy, 0); //Enable them....

This just makes windows think that you are running a screen saver, so it doesn;t allow those keys.... Check it out...pretty easy, eh?

-Viktor
--Ivanov
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>SystemParametersInfo (97, 1, &Dummy, 0); //Disable those keys....
Interesting... I just walked over to the Win95 box (where a screensaver (which is nothing but an ordinary application) was running, touched the ALT key... and - what do you think the result was? ;-)

BTW: A question of style ... 97 == SPI_SCREENSAVERRRUNNING

AND from the docs:
SPI_SCREENSAVERRUNNING
 Windows 95 only: Used internally; applications should not use this flag.
 
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
well, that's just a hack since there is no other way to accomplish it... maybe hooks would work, but it's a hard work too..

-Viktor
--Ivanov
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
I think jkr's point was that the SystemParemetsInfo() approach does not work.  (although the test may not be fair, it is possible that the screen saver doesn't actually set this!).
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
It does work, since I've tried it, and have used it... so it does work...
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
jkr, please tell us what your point was? Work? doesn't work? PLease tell us...
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>although the test may not be fair

It isn't fair, indeed - i just was curious and tried it...

But, as screensavers are simply executables with an extension named '.scr', i doubted that it works...
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
what do you mean it's not fair? Is anything in life fair? Well, not exactly.. You gotta cheat sometimes, and this is the time to do so... There is not such a thing as fair when talking about programming... You are trying to do everything posible to accomplish something even though you use methods that you would usually use... Well, that's what I have to say...

-Viktor
--Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
AND as jkr mentioned, a screen saver is a an EXE after all, so it is okay to use that method if you ask me...
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>a screen saver is a an EXE after all
That's why i doubt that it works - BLOCKING keys means that NO apllication will get notified about a keypress...
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
It blocks only the Windows-Keys and not all of them... only the Ctrl-Alt-Del, Alt-Tab and the rest of them...

jkr, Did you try it at all? You doubt, but oyu have not tried it...

-Viktor
--Ivanov
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Well, it's up to sbartok to try it ;-)
But you're right, i (personally) haven't tried it (as it don't like windows' keyboards, i'd have to start another PC that has one - and i'm going to finish for today, 10:15pm here ...)
0
 
LVL 1

Author Comment

by:sbartok
Comment Utility
SystemParametersInfo (97,...
just tells Windows to wait for Mouse Input, not for Keyboard
presses. That's the deal.
(referal url : mk:@ivt:pdref/native/sdk/win32/func/src/f87_17.htm
 referal SPI_SETKEYBOARDPREF
 Microsoft says : This function is intended for use with applications, such as the Control Panel, that allow the user to customize the Windows environment.)

Calling the f(x) results in disabling all Windows keys except the
Escape key for the active application (Dialog app,close with esc)

Also Hooks, the political 'correct' way (I think so :-) to do it
works perfectly.

Both of you had very good ideas, so : JKR try my "Q for JKR".

Thanks very much
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now