Solved

Locking Windows 95/98

Posted on 1999-01-21
24
188 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
ID: 1184752
The only way I've seen is to write a special keyboard driver.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1184753
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
ID: 1184754
Ooops, tach' auch Sacha! Und Danke für den Weihnachtsgruß ;-)

Jürgen <s>
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 22

Expert Comment

by:nietod
ID: 1184755
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
ID: 1184756
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
ID: 1184757
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
ID: 1184758
jetzda, juergen, hi !
hab schnell ins adressbuch geschaut und klingeling hats gemacht.
sorry :-)
0
 
LVL 22

Expert Comment

by:nietod
ID: 1184759
>> 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
ID: 1184760
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
ID: 1184761
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
ID: 1184762
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
ID: 1184763
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
 
LVL 86

Expert Comment

by:jkr
ID: 1184764
>>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
ID: 1184765
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
ID: 1184766
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
ID: 1184767
It does work, since I've tried it, and have used it... so it does work...
0
 
LVL 10

Expert Comment

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

Expert Comment

by:jkr
ID: 1184769
>>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
ID: 1184770
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
ID: 1184771
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
ID: 1184772
>>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
ID: 1184773
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
ID: 1184774
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
ID: 1184775
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

810 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