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

x
?
Solved

d4 - onshortcut

Posted on 1999-06-23
13
Medium Priority
?
660 Views
Last Modified: 2010-04-06
hi, guys.

problem w/ d4's onshortcut event:
i wanna know, if it's Fx or shift-Fx or ctrl-Fx etc.
is there a proper solution 4 the onshortcut-event or do i have 2 use OnKeyDown (or mayb directly programming the api?)?

question edited:
o.k., i found it: getkeyboardstate.
but how can i distinguish between lshift and rshift etc. i've tried as specified in win32.hlp, but it didn't work...
0
Comment
Question by:BlackDeath
[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
  • 7
  • 5
13 Comments
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384215
Edited text of question.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1384216
What OnShortCut event are you talking about? What component is it?

Yours,

Alex
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384217
it's a TForm event in Delphi4.
0
Technology Partners: 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!

 
LVL 1

Author Comment

by:BlackDeath
ID: 1384218
Edited text of question.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1384219
here is example of getkeyboardstate which you will see which shift key was pressed:


pas file:

unit GetKeyNameText_Form1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, mmsystem, ComCtrls, Tabnotbk;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Panel1: TPanel;
    StaticText1: TStaticText;
    StaticText2: TStaticText;
    StaticText3: TStaticText;
    StaticText4: TStaticText;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  protected
    procedure WndProc(var Msg:Tmessage); override;

  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WndProc(var Msg: TMessage);
var
  lpString: PChar;   // holds the key name
begin
  {if the message was a keystroke message...}
  if Msg.Msg = WM_KEYDOWN then
  begin
    {retrieve the name of the key pressed}
    lpString := StrAlloc(100);
    GetKeyNameText(Msg.LParam, lpString, 100);
    StaticText1.Caption := lpString  + ' Key Was Pressed';
    StrDispose(lpString);

    {indicate if the Shift Key was pressed}
    if HiByte(GetKeyState(VK_SHIFT)) <> 0 then
      StaticText4.Font.Color := clRed
    else
      StaticText4.Font.Color := clBlack;

    {indicate if the Ctrl key was pressed}
    if HiByte(GetKeyState(VK_CONTROL)) <> 0 then
      StaticText3.Font.Color := clRed
    else
      StaticText3.Font.Color := clBlack;

    {indicate if the Alt key was pressed}
    if HiByte(GetKeyState(VK_MENU)) <> 0 then
      StaticText2.Font.Color := clRed
    else
      StaticText2.Font.Color := clBlack;
  end;

  {pass all messages to the window procedure}
  inherited WndProc(Msg);
end;

procedure TForm1.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
  inherited;

  {this forces the system to send all keys to the form}
  Message.Result := Message.Result or DLGC_WANTALLKEYS or DLGC_WANTARROWS
    or DLGC_WANTTAB;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  Close;
end;

end.





dfm file:


object Form1: TForm1
  Left = 243
  Top = 148
  BorderStyle = bsDialog
  Caption = 'GetKeyNameText Example'
  ClientHeight = 138
  ClientWidth = 273
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 88
    Top = 112
    Width = 68
    Height = 13
    Caption = 'Press Any Key'
  end
  object Panel1: TPanel
    Left = 16
    Top = 24
    Width = 249
    Height = 25
    BevelInner = bvLowered
    Caption = 'Panel1'
    TabOrder = 0
    object StaticText1: TStaticText
      Left = 2
      Top = 2
      Width = 245
      Height = 21
      Align = alClient
      Alignment = taCenter
      TabOrder = 0
    end
  end
  object StaticText2: TStaticText
    Left = 48
    Top = 56
    Width = 40
    Height = 25
    Caption = 'ALT'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Times New Roman'
    Font.Style = []
    ParentFont = False
    TabOrder = 1
  end
  object StaticText3: TStaticText
    Left = 104
    Top = 56
    Width = 53
    Height = 25
    Caption = 'CTRL'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Times New Roman'
    Font.Style = []
    ParentFont = False
    TabOrder = 2
  end
  object StaticText4: TStaticText
    Left = 168
    Top = 56
    Width = 57
    Height = 25
    Caption = 'SHIFT'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -19
    Font.Name = 'Times New Roman'
    Font.Style = []
    ParentFont = False
    TabOrder = 3
  end
end

does tht help?
Regards Barry
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384220
hi, inthe.

thanx 4 your comment.
i've figured it out in between:

in formshortcut i test msg.charcode for the key i want and  with (getkeystate(vk_shift) and $80 = $80) i test if in the same moment the shift key is pressed (so it's quite similar 2 what u proposed).

the real problem is that win9x doesn't support vk_rshift, vk_lshift, vk_rcontrol etc., but nt does.

now i've tested out that in msg.keydata one can distinguish between left and right shift, control, alt.

i'm gonna do it that way.
i've gotta do that via onshortcut, cos this one passes the handled parameter, so i can set the message 2 handled := true, since i don't want the form 2 get the particular message after i've treated it my way.
i know there's a way 2 receive the handled parameter via an api message func, but since onshortcut exists, i wanna use it.

if u can tell me now how msg.keydata is composited (every single bit) - that'd b great. it's no prob 2 test the values i need out, but that's not the whole thing.
in general, i'd like 2 have a full explanation of the TWMKey's record fields "msg", "keydata" and "result".

mayb u can tell me something.
anyway, 4 your answer was quite good, i'll give u the points if u post an answer.

have a nice day,

BlackDeath.


0
 
LVL 17

Expert Comment

by:inthe
ID: 1384221
Hi BlackDeath
>>i know there's a way 2 receive the handled parameter via an api message func
>>TWMKey's record fields "msg", "keydata" and "result".

i am currently looking more into it myself at the moment as i recently came accross a situation where i needed to use keydown event and have the handled event as well.so i would also like to get the handled message via api(or let windows know i have dealt with the keys and not to do anything with them)  so i posted a question in the following newsgroup
borland.public.delphi.api about it so i see what responses it get.ill let you know anything i can find out more on.
Regards Barry

0
 
LVL 17

Expert Comment

by:inthe
ID: 1384222
thats borland.public.delphi.winapi
and the question title:
TWMKey's  "msg", "keydata" and "result"
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384223
thanxsofar,

BlackDeath.
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384224
uuurgh.

i've found a way 2 distinguish left&right shift, control & alt in win9x. but.

the right alt key generates 2 messages:

1st left control
2nd left menu

is this normal or is my equipment stoned?

btw:
i've handled the whole crap via Application.OnMessage and an AppMessage function which handles the TMsg. this worx quite good. the state of shift, ctrl, alt is not checked via getstate, but by evaluating the parameter lParam of TMsg.

i'm not through with this!

bye,

BlackDeath.

0
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 1384225
Hi
glad to be of some help,but i do wish i could have got more info for ya.

Regards Barry
0
 
LVL 1

Author Comment

by:BlackDeath
ID: 1384226
he barry - don't worry, as i told ya, it lead me on the right track.

thanx & bye,

BlackDeath.
0
 
LVL 17

Expert Comment

by:inthe
ID: 1384227
have asked more questions on this in newsgroups and am still waiting replys...will update if i get anything usefull
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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