Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CTRL Down/Up ????

Posted on 1998-07-22
7
Medium Priority
?
521 Views
Last Modified: 2008-02-01
Hi

I would like to know if it is possible to aks Delphi/Windows for the current state of the Shift, Alt and Ctrl keys. I emagine something like:

function GetCurrentShiftState: TShiftState;

...and the use it like...

...
SS : TShiftState;
...
SS := GetCurrentShiftState;
...

Exactly what I want to do is on a given time to be able find out if the Ctrl-button is up og down.
Can anyone please help me solve my problem.

Thanx - Steff
0
Comment
Question by:steff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358423
Hi steff,

You can get the keyboard state in a timer with, say, 100 ms interval. I j

       VAR KS : TKeyboardState;
       ...
       GetKeyboardState(KS);
       IF Odd(KS[VK_CAPITAL]) THEN {caps lock is down}
       ... VK_NUMLOCK
       ... VK_SCROLL
       ... VK_INSERT

Zif.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358424
i believe you should use VK_Control.
0
 

Author Comment

by:steff
ID: 1358425
Hi ZifNab

I'm not sure I understand what you mean - would you please explain alittle more.

Steff
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:steff
ID: 1358426
Hi ZifNab

I'm not sure I understand what you mean - would you please explain alittle more.

Steff
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 150 total points
ID: 1358427
Hi steff,

You can check yourself each time if ctrl is pushed :

If you use this code :

function CtrlDown : Boolean;
var  State : TKeyboardState;
begin
  GetKeyboardState(State);  
  Result := ((State[vk_Control] And 128) <> 0);
end;

function ShiftDown : Boolean;
var  State : TKeyboardState;
begin
  GetKeyboardState(State);  
  Result := ((State[vk_Shift] and 128) <> 0);
end;

function AltDown : Boolean;
var  State : TKeyboardState;
begin
  GetKeyboardState(State);  
  Result := ((State[vk_Menu] and 128) <> 0);
end;

----
you can also use this code (now you will be notified when the ctrl button is pressed):

First: set the form's KeyPreview := true;

Then:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in shift) then
ShowMessage('Ctrl is pressed');
end;

---

Kind regards, Zif.

0
 

Author Comment

by:steff
ID: 1358428
Hi Zif

Thanx alot for your answer. What I actualy got out of it was that I got to know the function GetKeyboardState and the type TKeyboardState - I didn't know them before.

I guess that a general problem for me is that I dont know enough about Windows-programming. Can you tell me how I can get a good .hlp file on windows-programming?

Am I right when I say that it is alittle strange that online help in Delphi says nothing about the functions that it ofers to windows - e.g. GetKeyboardState?
If it had just metioned it I would have found it in there - but the again, you would not have had this question at the following points  ;-)

BTW I think that your second idea...

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssCtrl in shift) then
ShowMessage('Ctrl is pressed');
end;

.would not have worked for me, since I can not be sure that the user pushes the CTRL-key when my application is active. What if the user pushes the CTRL key down, holds it down and then activates my application. If he now does the thing that makes me want to know if CTRL is down, I would (by this method) know that the CTRL-key actualy is down !?!?!?

Thanx Steff
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1358429
Yep, delphi manual has some lacks... sorry, don't know od a very good .hlp file. Everything I know of these functions is because I somewhere found them on the net.

About ctrl-key. I don't know if second idea works, haven't tried it the way you propose it.

Zif.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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