Shortcut key have problems - livecode

I have got some of coding for Shortcut. but my problem is I have Scrolling filed when performing the shortcut key event then its also place particular key to the Scrolling field eg: if I press alt+b then the b placed inside scrolling field
on rawKeyDown theKeyNumber
switch (theKeyNumber)
case 98 -- b
if the altKey is down then
answer"Hai"
end if
break
end switch
pass rawKeyDown
end rawKeyDown

The behavior you're seeing is occurring because you're not exiting the rawKeyDown handler when the altKey is detected. Try this:
on rawKeyDown theKeyNumber
switch (theKeyNumber)
case 98 -- b
if the altKey is down then
answer "Hai"
exit rawKeyDown #<---EXIT HERE
end if
break
end switch
pass rawKeyDown
end rawKeyDown

Related

Excel VBA: string comparison does not work

I am trying to compare an activeSheet code name with simple string, but the result is always true. I debbuged that and the variables values are different.
Sub Button_Supprimer()
Dim a, b As String
a = CStr(ActiveSheet.CodeName)
b = "Sheet1"
If (a = b) Then:
frmSupprimer.Caption = "Supprimer un matériel"
'frmSupprimer.UserForm_Initialize ("Matériel")
frmSupprimer.Show
End
End Sub
result
The result isn't always true, it's just that no statement in your code is actually conditional.
The existence of the : instructions separator token should generally be forgotten and left for golfed-up minimized fire-and-forget code that you would run from the immediate pane (Ctrl+G).
By terminating If {condition} Then with a colon, you have made the conditional expression be just an empty instruction.
Without it, the code stops compiling and you get a "If block without End If" compile error.
The correct syntax for a conditional block of code is as follows:
If {condition} Then
{conditional statements}
End If
Note that the End instruction is essentially a nuclear option for terminating the execution of the program; globals get reset to their default values, the execution context is terminated: rule of thumb, you want to let execution reach the End Sub statement and let the VBA runtime unwind its call stack normally: the End instruction stops everything dead in its tracks right there & then - and it's very, very rare that you actually need to do this.

AppleScript IOBluetooth issue, but only when exported as an app

Based on https://stackoverflow.com/a/57776820/2654603 I am using the IOBluetooth framework to detect disconnect/reconnect of my keyboard, such that switching it to a second host triggers changing the display input to that host as well.
When I run it in Script Editor it detects both connected and disconnected states as I switch back and forth. When I export it as an App (with Run-only) and run it, it starts out detecting the correct state. However once the keyboard has disconnected and later reconnects it never detects the connected state again.
If it matters, I'm on Catalina (10.15.7) on a 2019 MacBook Pro.
use framework "IOBluetooth"
use scripting additions
property lastStatus : true
set debug to true
set myKeyboard to "Keychron"
repeat
set kbStatus to isDeviceConnected(myKeyboard)
if kbStatus is not equal to lastStatus then
if debug is false then
if kbStatus is true then
do shell script "/usr/local/bin/ddcctl -d 1 -i 27"
else
do shell script "/usr/local/bin/ddcctl -d 1 -i 17"
end if
else
log "Status changed to " & kbStatus
end if
set lastStatus to kbStatus
end if
delay 1
end repeat
on isDeviceConnected(substring)
repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
if (device's nameOrAddress as string) contains substring then
if device's isConnected then
return true
else
return false
end if
end if
end repeat
return false
end isDeviceConnected
Edit: I have inserted lots of debug log messages in various places. When it fails to detect the reconnect, it is still matching my keyboard name in the pairedDevices() list, just not as connected.
I suspect the problem is that you didn't add parentheses to some of your objC methods, specifically: nameOrAddress() and isConnected(). I'll add that it's far better to use an idle loop than an endless repeat loop. That would look like this:
property lastStatus : true
property debug : true
property myKeyboard : "Keychron"
on idle
set kbStatus to isDeviceConnected(myKeyboard)
if kbStatus is not equal to lastStatus then
if debug is false then
if kbStatus is true then
do shell script "/usr/local/bin/ddcctl -d 1 -i 27"
else
do shell script "/usr/local/bin/ddcctl -d 1 -i 17"
end if
else
log "Status changed to " & kbStatus
end if
set lastStatus to kbStatus
end if
return 1
end idle
But set all that aside, because I think the best solution is to use the IOBluetoothDevice methods for registering observers. That way your app will sleep quietly in the background until it gets a notification that a device has been connected or disconnected. Copy the following script into Script Editor:
use AppleScript version "2.4" -- Yosemite 10.10 or later
use framework "IOBluetooth"
use scripting additions
property IOBluetoothDevice : class "IOBluetoothDevice"
property myKeyboard : "Keychron"
property connectionNotifObj : missing value
property disconnectionNotifObj : missing value
on run
try
set connectionNotifObj to IOBluetoothDevice's registerForConnectNotifications:me selector:"didConnectNotif:forDevice:"
on error errstr
display dialog errstr
end try
end run
on quit
try
connectionNotifObj's unregister()
end try
set connectionNotifObj to missing value
continue quit
end quit
on didConnectNotif:notif forDevice:dev
if (dev's nameOrAddress() as text) contains myKeyboard then
set disconnectionNotifObj to (dev's registerForDisconnectNotification:me selector:"didDisconnectNotif:forDevice:")
end if
end didConnectNotif:forDevice:
on didDisconnectNotif:notif forDevice:dev
if (dev's nameOrAddress() as string) contains myKeyboard then
try
disconnectionNotifObj's unregister()
end try
set disconnectionNotifObj to missing value
end if
end didDisconnectNotif:forDevice:
Save the script as an application — make sure you click the stay open after run handler checkbox so the script app doesn't auto-quit — and you should be good to go.
If you want the script app to be invisible to the Dock and App Picker, run the following command in terminal:
defaults write '/path/to/$name.app/Contents/Info.plist' LSUIElement -bool yes
Of course, that makes quitting it manually a bit more of a headache (you'll have to use Terminal or Activity Monitor to see it running), but it's visually more pleasing.

How to find whether a certain bluetooth device is connected?

I want to use applescript to do a periodic (every second) check to see if a specific bluetooth devices is connected, and if so, to flash up a quick notification. To frame it, I want a popup when my Airpods connect, since sometimes when I pull them out, the connect to my computer, and sometimes to my iPhone.
I've got everything figured out, except for the bluetooth check part. I've used this as a starting point, but can't get it to work. Any help would be appreciated.
repeat
set statusOld to checkStatus()
set statusNew to checkStatus()
repeat while statusOld is equal to statusNew
delay 1 --for 1 second checks
set statusNew to checkStatus()
end repeat
if statusNew is true then
display dialog "Device Added - put some real code here"
else
display dialog "Device Removed - put some real code here"
end if
end repeat
on checkStatus()
(*Delete the 2 lines below when done testing*)
--set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
--set myString to "name: DR-BT101 Connected: " & myString
(*uncomment line below when done testing*)
set myString to do shell script "system_profiler SPBluetoothDataTyp"
--initial check if it's not even there
if myString does not contain "Christian’s AirPods" then
return false
else
--find out if connected/disconnected
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString --each item of mylist is now one of the devices
set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains "Christian’s AirPods" then
if item counter of myList contains "Connected: Yes" then
return true
else if item counter of myList contains "Connected: No" then
return false
else
display dialog "Error Parsing" --this shouldn't happen
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus
You're missing the e:
set myString to do shell script "system_profiler SPBluetoothDataType"
^
I'm working on something similar. This seems to work well on macOS Mojave:
use framework "IOBluetooth"
use scripting additions -- https://stackoverflow.com/a/52806598/6962
on isDeviceConnected(substring)
repeat with device in (current application's IOBluetoothDevice's pairedDevices() as list)
if device's isConnected and (device's nameOrAddress as string) contains substring then return true
end repeat
return false
end isDeviceConnected
-- Usage example:
isDeviceConnected("AirPods")
I combined it with a launch agent like this: https://gist.github.com/henrik/3d4c622a5567cdf2bf461352f48ad4dd

Login form have some problems

I am beginner in Livecode. I got some code for log in. My problem is I want to convert the password to "*" How i change the following code
local sUsername, sPassword
on openCard
put "johnsmith" into sUsername
put "pa55word" into sPassword
end openCard
on loginCheck
if field "username" is sUsername and field "password" is sPassword then
answer "Login Successful"
go to card "accessed"
else
answer "Details Incorrect. Please try again!"
end if
end loginCheck
One simple method is to use the keyDown message along with a custom property to store the clear text. Place the following code in the password field's script:
on keyDown theKey
-- RESTRICT THE ALLOWED KEYS TO SOME DEFINED CHARACTERS
if theKey is not in "abcdefghijklmnopqrstuvwxyz1234567890" then exit keyDown
put the hiddenText of me into temp
put theKey after temp
set the hiddenText of me to temp
put "*" after me
end keyDown
on backspaceKey
set the hiddenText of me to empty
set the text of me to empty
end backspaceKey
The second line in the keyDown handler lets you limit the characters that are accepted for the password to a defined list (you could include special characters such as "#" and "_" and others if you wish). The backspaceKey handler is used to delete any entered characters and start over.
Note that you may want to handle special cases such when the enterKey and/or returnKeys are pressed, which often trigger the submission of a form.

OnKey "Delete" clear combobox

I have a userform with multiple comboboxes. User can type in a new item or pick one from the list.
He can start typing first letters of wanted item but when he makes a mistake and starts with e.g. "b" instead of "n" he has to clear the combobox manually or find the item on the list using mouse or arrows.
I would like to quickly clear the box using the delete key so the user can start typing again. But I don't know where to put this line of code if correct (enter event, change event, some other maybe?).
Application.OnKey "{Delete}", "WyczyscPole"
First Excel needs to know which box the user is in, and then clear it.
I tried to create separate module with a variable that finds out the current combobox name and clear it in next step. But I don't know whether called sub below is even correct.
Sub WyczyscPole()
Dim NazwaPola As ComboBox
NazwaPola = frmZakupy.ActiveControl.Name
NazwaPola.Clear
End Sub
You can use the KeyDown event to capture the Delete key (KeyCode = 46) when the user is in the combobox.
Private Sub NazwaPola_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 46 Then
Me.NazwaPola.Value = vbNullString
End If
End Sub
Please try: frmZakupy.value=''
It's a good practice to don't use special characters like 'ś','ć' in any names.

Resources