Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Traping Windows keys ... 1

Status
Not open for further replies.

ShyFox

Programmer
Mar 22, 2003
210
ES
Can you tell me how can I trap the windows keys ????

I wanna to do something like this:

[blue]If nKeyCode[/blue]=[blue]Left Windows Key[/blue]
[green]* do something[/green]
[blue]If nKeyCode[/blue]=[blue]Right Windows Key[/blue]
[green]* do something else[/green]
[blue]EndIfIf[/blue]

But I didn't find the codes or the labels of those keys.
Strange ... very strange ...

Regards

As I go deeper the road seems to go further. We're just simply pasangers on the road of knowledge.
 
It will be like trapping the Print Screen key. Windows grabs the key before Fox ever knows about it. An API call of some sort would be able to get at it but passing that back to Fox? I'm not sure about that.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
ShyFox,

The window key doesn't fire the KeyPress event in VFP

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
ShyFox,

As Slighthaze already mentioned, Windows key doesn't fired the keypress event. So you have to Hook into the LowLevel Keyboard. But this technique cannot be implement with VFP because it needs a callback function (need a wrapper)

The code below is just to show how to find out when the WinKey is pressed, but it doesn't / cannot trap the key itself.

---------------------
Declare Short GetKeyState in Win32API Integer KeyCode
Declare Sleep in Win32API Long nTimeout

lMore = .T.
Set escape off

Do while lMore
cKey = ''
If (GetKeyState(0x1B) < 0) && Escape key
lMore = .F.
endif

If lMore
If (GetKeyState(0x5B) < 0)
cKey = cKey + iif(empty(cKey), 'Left WinKey', '-Left WinKey')
endif

If (GetKeyState(0x5C) < 0)
cKey = cKey + iif(empty(cKey), 'Right WinKey', '-Right WinKey')
endif

If !empty(cKey)
Wait cKey + ' key pressed' window nowait noclear
endif
Sleep(20)
endif
enddo

Clear Dlls
Wait clear
Set escape on
---------------------

Hope that helps
Regards


-- AirCon --
 
AirCon (IS/IT--Manageme)
Good. Now how can you simulate it? Make windows think that the user presed the win key.
Regards

As I go deeper the road seems to go further. We're just simply pasangers on the road of knowledge.
 
ShyFox,

Do you mean how to put the code into form ?
If that's what you mean, then you can create a timer with 30-60 for interval

*** Form Load/Init event
Declare Short GetKeyState in Win32API Integer KeyCode
Declare Sleep in Win32API Long nTimeout


*** Form Unload
Clear Dlls
Wait clear


*** Timer event
Local cKey

cKey = ''
If (GetKeyState(0x5B) < 0)
cKey = cKey + ;
iif(empty(cKey), 'Left WinKey', '-Left WinKey')
endif

If (GetKeyState(0x5C) < 0)
cKey = cKey + ;
iif(empty(cKey), 'Right WinKey', '-Right WinKey')
endif

If !empty(cKey)
Wait cKey + ' key pressed' window nowait noclear
endif


-- AirCon --
 
AirCon (IS/IT--Manageme)
No, no, no ... but I give you a star for this. You showed me a easier way to translate it into a form code.
I wanted to ask how can you programatically press the Win Keys.
Not only to watch them.
Regards

As I go deeper the road seems to go further. We're just simply pasangers on the road of knowledge.
 
AirCon (IS/IT--Manageme)
Sorry for the star. I'll give it to you later. It gave me an error with the diagnostic on it. Maybe the admin will fix it. Still trying to mark you with that star.
Regards

As I go deeper the road seems to go further. We're just simply pasangers on the road of knowledge.
 
ShyFox

Sorry for the star
No problem, it's ok :)

To programmatically press WinKey:
-------------------
Declare keybd_event in User32 ;
Short bVK, Short bScan, Long nFlags, Long dwExtraInfo

keybd_event(0x5B, 0, 0x01 , 0 )
keybd_event(0x5B, 0, 0x03, 0 ) && Left WinKey
Wait 'Press any key...' window

keybd_event(0x5C, 0, 0x01 , 0 )
keybd_event(0x5C, 0, 0x03, 0 ) && Right WinKey
Clear Dlls

-------------------

Regards

-- AirCon --
 
Forgot to tell you this.
Don't run the code from VFP command window, because the command is a pair for each key

Regards

-- AirCon --
 
AirCon (IS/IT--Manageme)

Forgot to tell you this.
Don't run the code from VFP command window, because the command is a pair for each key

Ok. Thanks

Gave the star that you do deserve for showing me the right way!
Thank you again!!!
Regards

As I go deeper the road seems to go further. We're just simply pasangers on the road of knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top