Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 10:52 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Num Lock and Caps Lock scripts?
PostPosted: July 13th, 2010, 3:31 pm 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
Hi,

I am designing a program which requires two things (in certain parts of the program):

-Num Lock to be forced ON
-Caps Lock to be forced OFF

I'm a complete script novice, so I don't know if these actions can be done using script. If they can, I'd very much like to know how. Any help would be much appreciated :)


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 13th, 2010, 6:14 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
SetKeyState("N",true) will turn on Num lock

SetKeyState("N",false) will turn off Num lock

SetKeyState("C",true) will turn on Caps lock

SetKeyState("C",false) will turn off Caps lock

You can also check for the state of a key by using
if ( SetKeyState( "N", true ) )
{
code
}

do you need help to attach the script to a trigger?

Sandy

_________________
Whoever designed this, never actually used it!


For this message sandyn has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 13th, 2010, 7:57 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
GetKeyState("C")

Will also work for checking.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 14th, 2010, 9:19 am 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
Thanks guys! We would most likely use an 'on page load' trigger - can we just put that script into the 'script' action with that trigger?

EDIT: Just tested and it works fine, cheers to both of you :)


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 15th, 2010, 10:07 am 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
Ok, here's another question:

Is there any script to completely disable a key, e.g Caps Lock?


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 15th, 2010, 12:40 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
There is no script to disable the key. I think it can be done through the registry, so if you have control of the PC, then that would be an option.... but not very nice.
You could check for the key state at certain critical times, then turn it off if it has been selected, but that may not be foolproof.
Another possibility is to register an event handler which turns off the key if someone selects it.

here is a starter for 10

Code:
myEvent = RegisterEventHandler("keydown", WhichKey)

function WhichKey(eventKeypress)
{


Click=eventKeypress.key

Debug.trace(Click+"key was pressed"+"\n")
}


this small code should go into a script object.
when you press a key, it will open a debug window and show which key was pressed. (Note if you use the keypress EVENT, it will only trigger on character keys, so will not work on caps lock and shify, but keydown EVENT will detect all keys).
In the function, you would have to check for caps lock key (code 20) being pressed, then turn it off. I'm not sure how much resource a handler uses, but you can register/unregister as required.

_________________
Whoever designed this, never actually used it!


For this message sandyn has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 15th, 2010, 12:58 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
I leave the office for some coffee and Sandyn's answer the question already...getting slow in my old age.

Anyway, was doing a different way - but same principle. Opus includes a trigger called key release - just press the CAPSLOCKs key in the box and it will activate whenever the key is pressed. Add Sandyn's original script to turn the key off every time the trigger is activated.

I've used a dozen key release triggers before on a publication with no hint of resource hogging.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 15th, 2010, 2:29 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
You deserve a coffee break for all the brilliant help you give people on here!!

_________________
Whoever designed this, never actually used it!


For this message sandyn has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: July 15th, 2010, 2:55 pm 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
sandyn wrote:
You deserve a coffee break for all the brilliant help you give people on here!!


I second this, mack - your solution works great. Thanks very much to both of you :)


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: January 31st, 2011, 12:02 pm 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
Sorry to bring up an old topic, but I need some help again...

What I'm trying to do is show a text box based on whether Caps Lock is on or not. The code I'm using in the script at the moment is as follows:

if ( ( "C", true ) )
{capscheck = "yes"}

capscheck is just the variable I'm using to display the text box.

At the moment, that variable is being set to "yes" regardless of whether Caps Lock is actually on or not.

Is there something I'm doing wrong? Any help would be greatly appreciated.


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: January 31st, 2011, 12:16 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Jay,

Add the following code to a trigger such as Key Release (Any):

Code:
GetKeyState("C") ? textBox.Hide() : textBox.Show()


It'll hide the object 'textBox' when Caps is on and show it when caps is off.

It's the same as

Code:
if (GetKeyState("C"))
{
//do something here
} else
{
//do something here
}


Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: Num Lock and Caps Lock scripts?
PostPosted: January 31st, 2011, 12:34 pm 
Offline

Joined: December 21st, 2009, 5:26 pm
Posts: 27
Opus: Professional 7.03
OS: XP SP3
Hi Mack,

Thanks, that worked great! :)


For this message JammyJayUK has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 32 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group